how to add Linebreak to a string in asp.net vb - asp.net

I tried everything, but nothing seems to work!
How the do I put a breakline?!
Dim textMsg as String
textMsg = Body.text & Environment.Newline & _ q1.text & Environment.Newline & _ q2.text & Environment.Newline & _ q3.text & Environment.Newline & _ q4.text '
please help
(with corrent code I get an error cuz of the & Environment.Newline & _ ")

Since you tagged this asp.net, I'll guess that this newline should appear in a web page. In that case, you need to remember that you are creating html rather than plain text, and html ignores all whitespace... including newlines. If you view the source for your page, you'll likely see that the new lines do make it to your html output, but they are ignored, and that's what is supposed to happen. If you want to show a new line in html, use a <br> element:
textMsg = Body.text & "<br>" & _ q1.text & "<br>" & _ q2.text & "<br>" & _ q3.text & "<br>" & _ q4.text
The code above will place the text on several lines. It's interesting that if you view the source now, you'll see that everything is all on the same line, even though it uses several lines for display.

You should add a br:
textMsg = Body.text & "<BR/>" & _ q1.text & "<BR/>" & _ q2.text & "<BR/>" & _ q3.text & "<BR/>" & _ q4.text
Or you can try:
Str & VBNewLine OR Str & VBCrLf
Or set the email message to html. The the will work.

thats the right one:
& (vbCrLf) &

Try this:
dim textMsg as String
textMsg = Body.text & vbNewLine

I preffer .Net Style:
& Environment.NewLine &
It's Is exactly the same that
& (vbCrLf) &

Related

Exporting Json data in asp.net vb from MS SQL

I am trying to export data from MS SQL out in a json format in my asp.net web forms application. Problem is it exports with two double quotes around the values instead of just one double quote.
I want it to export like this:
{"bizunitid":"11111","prodlineid":"1","reasonforsurvey":"1"}
but it is coming out like this:
"{""bizunitid"":""11111"",""prodlineid"":""1"",""reasonforsurvey"":""2""}"
I have tried replacing the two double quotes but it always returns two double quotes.
Dim json As String = cmd.ExecuteScalar
streamWriter.Write(json.Replace("""""", Chr(34)))
Not sure if this is what you're looking for, but it's how I've done it when posting JSon to an API for a messaging app with VB.Net:
MessageTitle = MessageTitle.Replace("""", """""")
MessageBody = MessageBody.Replace("""", """""")
Dim strPostData As String = "{" &
"""notification"": {" &
"""sound"": ""default""," &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}, " &
"""data"": {" &
"""title"": """ & MessageTitle & """," &
"""body"": """ & MessageBody & """" &
"}," &
"""to"": """ & strRegIDs & """," &
"""priority"": 10 " &
"}"
hopefully that helps a bit

Podcast rss feed reading itunes image in classic asp

I'm working on a rss feed reader and seems so work great.
The only thing that I seem not to get working is to read the image in the feed.
<itunes:image href="http://www.itunes.com/image.jpg"/>
Can anyone help?
This is a part of my code.
For Each objItem in objItems
On Error Resume Next
TheTitle = objItem.selectSingleNode("title").Text
TheLink = objItem.selectSingleNode("image").Text
Theimg = objItem.SelectSingleNode("itunes").Attributes(":image").InnerText
Response.Write "<div class='article'>" &_
"<a href=" & TheLink & ">" & _
"<span>" & Theimg & TheTitle & "</span>" & _
"</a>" & _
"</div>"
Next
Your image address needs to go inside an image tag
Response.Write "<div class=""article"">" &_
"<a href=""" & TheLink & """>" & _
"<img src=""" & Theimg & """ alt=""" & TheTitle & """ />" & _
"</a>" & _
"</div>"
If you're wondering why all the double quotes, see this question
Adding quotes to a string in VBScript
As an aside, if you understand XSL then I find that the best way to handle RSS feeds in Classic ASP is to do a server side XSLT transformation. The ASP looks like this
set xml = Server.CreateObject("Msxml2.DomDocument.6.0")
xml.setProperty "ServerHTTPRequest", true
xml.async = false
xml.validateOnParse = false
xml.load("http://your-rss-feed")
set xsl = Server.CreateObject("Msxml2.DomDocument.6.0")
xsl.load(Server.Mappath("yourxslfile.xsl"))
Response.Write(xml.transformNode(xsl))
set xsl = nothing
set xml = nothing

asp.net json.net parse results

I´m not familiar with JSON data parsing. So far, this is what I´ve come up to through web research:
data to parse:
https://api.twitch.tv/kraken/streams/
I´m trying to use the JSON.NET/VB.NET framework to do so:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
'(inside a function)
Dim json As JObject = JObject.Parse("https://api.twitch.tv/kraken/streams/")
strResult As String = json.SelectToken("streams").SelectToken("game")
It´s returning me an error message, and I´m sure I don´t have the structure right. How could I make this work? And afterwards, I´d like to loop through the results of the returning array.
Thanks,
This should get you going (just a conceptual example - console, not asp.net):
Dim json As JObject = _
JObject.Parse(New WebClient().DownloadString("https://api.twitch.tv/kraken/streams/"))
If json IsNot Nothing AndAlso json.HasValues Then
If json.SelectTokens("streams") IsNot Nothing _
AndAlso json.SelectTokens("streams").Children().Any() Then
Dim games() As JToken = json.SelectTokens("streams").Children().ToArray()
For Each child As JToken In games
Console.WriteLine("game title: {0} game id: {1} for mature audience? {2}", _
child.Item("game"), child.Item("_id"), child.Item("channel").Item("mature"))
Console.WriteLine()
Next
Console.ReadLine()
End If
End If
Hth....
This is the code simplified, with the help of EdSF, for the newbies in json (like myself):
Dim apiURL As String = "https://api.twitch.tv/kraken/streams?limit=10&offset=0"
Dim json As JObject = JObject.Parse(New WebClient().DownloadString(apiURL))
If json IsNot Nothing AndAlso json.HasValues Then
If json.SelectTokens("streams") IsNot Nothing AndAlso json.SelectTokens("streams").Children().Any() Then
Dim games() As JToken = json.SelectTokens("streams").Children().ToArray()
For Each child As JToken In games
'Console.WriteLine("game title: {0} game id: {1} for mature audience? {2}", child.Item("game"), child.Item("_id"), child.Item("channel").Item("mature"))
'Console.WriteLine()
lblMensagemSucesso.Text &= "_id=" & child.Item("_id").ToString() & "<br>"
lblMensagemSucesso.Text &= "game=" & child.Item("game").ToString() & "<br>"
lblMensagemSucesso.Text &= "viewers=" & child.Item("viewers").ToString() & "<br>"
lblMensagemSucesso.Text &= "preview=" & child.Item("preview").ToString() & "<br>"
lblMensagemSucesso.Text &= "preview.small=" & child.Item("preview").Item("small").ToString() & "<br>"
lblMensagemSucesso.Text &= "<img src='" & child.Item("preview").Item("small").ToString() & "'/><br>"
lblMensagemSucesso.Text &= "_links.self=" & child.Item("_links").Item("self").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.status=" & child.Item("channel").Item("status").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.logo=" & child.Item("channel").Item("logo").ToString() & "<br>"
lblMensagemSucesso.Text &= "<img src='" & child.Item("channel").Item("logo").ToString() & "'/><br>"
lblMensagemSucesso.Text &= "channel.video_banner=" & child.Item("channel").Item("video_banner").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.url=" & child.Item("channel").Item("url").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel.views=" & child.Item("channel").Item("followers").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel._links.self=" & child.Item("channel").Item("_links").Item("self").ToString() & "<br>"
lblMensagemSucesso.Text &= "channel._links.teams=" & child.Item("channel").Item("_links").Item("teams").ToString() & "<br>"
lblMensagemSucesso.Text &= "<br>"
Next
'Console.ReadLine()
End If
End If

Getting Syntax error when executing ASP ADO Insert

I am concatenating different values and I get the following sql statement:
INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder ) VALUES ('left','1','left1','',1024,768,'FILE1',1)
I really do not see here any errors, however, it says me
Microsoft JET Database Engine error '80040e14'
Syntax error in INSERT INTO statement.
/adm/uploadAdPic.asp, line 68
sql="INSERT INTO Ads (Position, Type, AdType, Link, Width, Height, Path, Korder )"
sql=sql & " VALUES "
sql=sql & "('" & position & "',"
sql=sql & "'" & adType & "',"
sql=sql & "'" & position & adType & "',"
sql=sql & "'" & link & "',"
sql=sql & "" & width & ","
sql=sql & "" & height & ","
sql=sql & "'" & path & "',"
//sql=sql & "" & korder & ","
sql=sql & "" & korder & ")"
//sql=sql & "0)"
Response.Write(sql)
//on error resume next
conn.Execute sql,recaffected //THIS IS LINE 68
Can you, please, help me to find syntax error.
EDIT:
I have found sollution by myself, but it also contains in the answer below.
Position is reserved word.
I tried to modify my insert statement removing different fields and I found out that Position field makes an error.
So I renamed Position to VertPos and it works.
Position is a reserved word in Jet SQL, try change to [Position].
As a general recommendation, add [] to all columns name.
sql="INSERT INTO Ads ([Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder] )"
sql=sql & " VALUES "
sql=sql & "('" & position & "',"
sql=sql & "'" & adType & "',"
sql=sql & "'" & position & adType & "',"
sql=sql & "'" & link & "',"
sql=sql & "" & width & ","
sql=sql & "" & height & ","
sql=sql & "'" & path & "',"
//sql=sql & "" & korder & ","
sql=sql & "" & korder & ")"
//sql=sql & "0)"
Response.Write(sql)
//on error resume next
conn.Execute sql,recaffected //THIS IS LINE 68
1) The error is because some of your column names happen to be MSSQL keywords:
' SUGGESTED CHANGE:
INSERT INTO Ads (
[Position], [Type], [AdType], [Link], [Width], [Height], [Path], [Korder])
VALUES ('left','1','left1','',1024,768,'FILE1',1)
2) You're probably much better off using a command object instead of a "naked insert":
Here's an example that shows how to use "objCom.parameters.append()":
http://www.freevbcode.com/ShowCode.asp?ID=3687

Syntax html in asp.net + vb.net

This my code
Dim verifyUrl As String = Request.Url.GetLeftPart(UriPartial.Authority) & Page.ResolveUrl("~/verify.aspx?ID=" & sGUID)
mail.Body = "<html>" & _
"<head>" & _
"<meta http-equiv=""Content-Language"" content=""fr"">" & _
"<meta http-equiv=""Content-Type"" content=""text/html; charset=windows-1252"">" & _
"</head>" & _
"<body>" & _
" <p>Hello, <%UserName%>. You are receiving this email because you recently created a new account at my" & _
"site. Before you can login, however, you need to first visit the following link:</p>" & _
"<p> //////Here put an href whit the value verifyUrl ///// </p>" & _
"</body>" & _
"</html>"
mail.Body = mail.Body.Replace("<%VerifyUrl%>", verifyUrl)
mail.Body = mail.Body.Replace("<%UserName%>", nom)
Try for long time to put an like <a href"<%verifyUrl%>"</a> but this not work well................
Please help me to enter this simple html line!!!
Thanks in advance!!
You can use this:
<a href='<%VerifyUrl%>'>Click Here</a>

Resources