SSIS Script Task Special Characters - ssis

I am trying to get some data from an API, using an SSIS Script Task with Visual Basic code. But I having some problems because I have Portuguese special characters in some fields. I was trying to solve my problems and I read that this could be achieved by enconding the data. I try to do this with any sucess.
Can anyone help me?
Regards
Using c As WebClient = New WebClient()
c.BaseAddress = URL
c.Headers(HttpRequestHeader.Authorization) = "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(key & ":" & pass))
c.Credentials = New NetworkCredential(key, pass)
Dim xml = c.DownloadString(URL & "CRUser?start=0&count=999&language=English")
'Parse para objetos
Dim doc = XDocument.Parse(xml)
Dim reader = doc.CreateReader()
Dim xRoot As XmlRootAttribute = New XmlRootAttribute()
xRoot.ElementName = "array"
xRoot.IsNullable = True
Dim xmls As New XmlSerializer(GetType(List(Of CRUser)), xRoot)
Dim _data As List(Of CRUser) = xmls.Deserialize(reader)
For Each item As CRUser In _data
'Console.WriteLine(item.id)
'Console.WriteLine(item.firstName)
'..... resto campos injetar no pipelino do SSIS os dados
MyOutputBuffer.AddRow()
MyOutputBuffer.id = item.id
MyOutputBuffer.firstName = item.firstName
Next
End Using

Related

How do I put a serialized object into a json file with visual basic?

I currently have data being pulled from textboxes and comboboxes that are converted into properties of an object, and then that object is seralized into json. I then use the streamwriter function to put that into a json file that has already been created but I just end up with a bunch of weird formatting and things not updating and being added.
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim monsterName As String
monsterName = TextBox2.Text
TextBox2.Text = ""
Dim monsterCB As Integer
monsterCB = TextBox3.Text
TextBox3.Text = ""
Dim monsterType As String
monsterType = ComboBox3.SelectedItem
ComboBox3.Text = ""
Dim Monster As New Monster
Monster.MonsterName = monsterName
Monster.MonsterCombatRating = monsterCB
Monster.MonsterType = monsterType
Dim output As String
output = JsonConvert.SerializeObject(Monster)
Dim file As System.IO.StreamWriter
file = My.Computer.FileSystem.OpenTextFileWriter("C:\Program Files (x86)\D&DLoot\data.json", True)
file.WriteLine(Monster)
file.Close()
End Sub
This is within my form code and is the snippet of when my button is clicked for the current form.
Then, in my json file it just writes a new line of
WinFormsApp1.Monster
So I'm not entirely sure whats going on and what I have missed. I can't see whats wrong with the code above.
Should be using output in the code below instead of monster. Since the serialized object is in the output, not the monster.
file.WriteLine(Monster)
output = JsonConvert.SerializeObject(Monster)

How to require login to view documents on a website?

My website has a series of documents stored in a folder on the webserver (Windows 2012 R2).
The documents can be found on a page that can only be accessed by logged in users. These documents are PDF files that can be downloaded through the click of a hyperlink. They also can be viewed in the web browser.
Currently a user can copy the URL, give it to somebody else and they can use it to download the PDFs thereby not having to go through the login process to view the page behind the login page.
Let's say the URL is https://www.mywebsite.com/documents/adocument.pdf
How can I go about securing these documents so that the url can't just be sent around but prompts for a login instead?
Below is the code to get the documents. An These are then pushed into an ASP.NET placeholder.
Public Shared Function GetLoanDocLinks(ByVal iLoanID As Integer) As String
Dim s As String
s = ""
Dim MyConn As FirebirdSql.Data.FirebirdClient.FbConnection
Dim Adaptor As FirebirdSql.Data.FirebirdClient.FbDataAdapter
Dim ds As DataSet
Dim dr As DataRow
Dim iNumRows, i As Integer
Dim MySQL As String
Dim myContext As HttpContext
Dim MySession As HttpSessionState = System.Web.HttpContext.Current.Session
myContext = HttpContext.Current
ds = New DataSet
'StrConn = ConfigurationManager.ConnectionStrings("FBConnectionString").ConnectionString
MySQL = "SQL statement goes here"
MyConn = New FirebirdSql.Data.FirebirdClient.FbConnection(DBNAME.ConnStr)
Adaptor = New FirebirdSql.Data.FirebirdClient.FbDataAdapter(MySQL, MyConn)
Adaptor.SelectCommand.Parameters.Add("#p1", FirebirdSql.Data.FirebirdClient.FbDbType.Integer).Value = iID
Try
Adaptor.Fill(ds)
Catch ex As Exception
GenExternals.LogEntry("Error:" & ex.Message)
End Try
iNumRows = ds.Tables(0).Rows.Count
For i = 0 To iNumRows - 1
dr = ds.Tables(0).Rows(i)
s = s & "<a href='documents/" & Trim(dr("Filename")) & "' target='+new'>" & Trim(dr("description")) & "</a> "
s = s & "<br /> "
Next
s = s & "<br />"
MyConn.Close()
Adaptor = Nothing
MyConn = Nothing
GetLoanDocLinks = s

Get First Vid From Youtube VB.NET

Im trying to get the first youtube link from youtube or google but I can't get it to work. can someone please help me out?
Dim m As New Regex("<a href=""/watch?v=.*""")
Dim request2 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www.youtube.com/results?search_query=" + ListBox1.SelectedItem + " " + ListBox2.SelectedItem)
Dim responseyoutube As System.Net.HttpWebResponse = request2.GetResponse
TextBox2.Text = (request2.Address.ToString)
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(responseyoutube.GetResponseStream())
Dim rssourcecodey As String = sr.ReadToEnd
Dim matches As MatchCollection = m.Matches(rssourcecodey)
TextBox1.Text = rssourcecodey
For Each itemcode2 As Match In matches
youtube = itemcode2.Value.Split("=").GetValue(1)
ListBox2.Items.Add(youtube)
? is a special meta char in regex which makes the previous token as optional one (not the one after * or +). So you need to escape the ? symbol in-order to match a literal ? symbol.
Dim m As New Regex("<a href=""/watch[?]v=.*""")
OR
Dim m As New Regex("<a href=""/watch\\?v=.*""")

Not able to open email attachment from bytes array

I am trying to attach a binary data retrieved from MySQL server to an email as attachment using VB.net.
I can send out a email with attachment but not able to open any of the attachment file even word file also is empty.
The error message is --> Adobe Reader could not open "xxx.pdf" because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
Been googled around but still not able to find out what is wrong with my code.
Anyone can help will be very appreciated!Thanks!
Dim m_ImageBinary As [Byte]() = New [Byte](-1) {}
Dim m_AttachmentType As String = ""
Dim m_AttachmentName As String = ""
Dim m_Attachment As Boolean = False
Dim cmd3 As New MySqlCommand("SELECT Attachment, AttachmentType, AttachmentName FROM tbcommunication WHERE CommunicationID = " & cid, MySql)
Dim rdr2 As MySqlDataReader = cmd3.ExecuteReader()
While rdr2.Read()
If rdr2("Attachment").ToString() <> "" Then
Dim m_Length As Integer = DirectCast(rdr2("Attachment"), [Byte]()).Length
m_ImageBinary = New [Byte](m_Length - 1) {}
m_ImageBinary = DirectCast(rdr2("Attachment"), [Byte]())
m_AttachmentType = rdr2("AttachmentType").ToString()
m_AttachmentName = rdr2("AttachmentName").ToString()
End If
End While
If m_ImageBinary.Length <> 0 Then
If m_Attachment = False Then
If m_AttachmentType.Contains("jpeg") OrElse m_AttachmentType.Contains("bmp") OrElse m_AttachmentType.Contains("gif") Then
m_Attachment = False
Else
m_Attachment = True
End If
End If
If m_Attachment = True Then
' If not image file
Response.AppendHeader("content-disposition", "attachment; filename=" & m_Atta`enter code here`chmentName)
End If
'Write(binary)
'Response.ContentType = m_AttachmentType
'Response.BinaryWrite(m_ImageBinary)
'Response.[End]()
End If
Dim mailmssg As New MailMessage()
Dim smtp_client As New SmtpClient
Using memoryStream As New MemoryStream()
Dim bytes As Byte() = memoryStream.ToArray()
Dim att As New Attachment(New MemoryStream(bytes), m_AttachmentName)
mailmssg.Attachments.Add(att)
MemoryStream.Dispose()
smtp_client.DeliveryMethod = SmtpDeliveryMethod.Network
smtp_client.Send(mailmssg)
End Using
'...
' memoryStream = new blank MemoryStream
Using memoryStream As New MemoryStream()
' get emtpy array from memoryStream
Dim bytes As Byte() = memoryStream.ToArray()
' Create empty MemoryStream from empty bytes array
Dim att As New Attachment(New MemoryStream(bytes), m_AttachmentName)
'...
With your current code you'll never send anything than an empty file with a name and always only one.

Trying to use a HTML file as my email body using iMsg in VB.NET

I've wrote a script to create a HTML file based on a SQL Query.... It has become necessary to have that HTML be emailed. Most of our execs use blackberry's and I want to send the HTML file as the body. I have found a round about way to get this done, by adding a WebBrowser, and having the web browser then load the file, and then using the below code to send. The problem i'm facing is if I automate the code fully, it will only email part of the HTML document, now if I add a button, and make it do the email function, it sends correctly. I have added a wait function in several different location, thinking it may be an issue with the HTML not being fully created before emailing. I have to get this 100% automated. Is there a way I can use the .HTMLBody to link to the actual HTML file stored on the C:(actual path is C:\Turnover.html). Thanks all for any help.
Public Sub Email()
Dim strdate
Dim iCfg As Object
Dim iMsg As Object
strdate = Date.Today.TimeOfDay
iCfg = CreateObject("CDO.Configuration")
iMsg = CreateObject("CDO.Message")
With iCfg.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "xxxxx.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = """Turnover Report"" <TurnoverReports#xxxxx.com>"
.Update()
End With
With iMsg
.Configuration = iCfg
.Subject = "Turnover Report"
.To = "xxxxx#xxxxx.com"
'.Cc = ""
.HTMLBody = WebBrowserReportView.DocumentText
.Send()
End With
iMsg = Nothing
iCfg = Nothing
End Sub
used the below function to read in a local html file. then set
TextBox2.Text = getHTML("C:\Turnover2.html")
and also
.HTMLBody = TextBox2.Text
Private Function getHTML(ByVal address As String) As String
Dim rt As String = ""
Dim wRequest As WebRequest
Dim wResponse As WebResponse
Dim SR As StreamReader
wrequest = WebRequest.Create(address)
wResponse = wrequest.GetResponse
SR = New StreamReader(wResponse.GetResponseStream)
rt = SR.ReadToEnd
SR.Close()
Return rt
End Function