angel Posted November 27, 2009 Posted November 27, 2009 Pls. help me with this error... 'Read the contents in to a byte array Dim objMyData() As Byte objMyData = CType(objMyRow("Document"), Byte()) <<<<<<<ERROR Dim objMyFile As New FileStream("C:\temp\document.doc", FileMode.OpenOrCreate, FileAccess.Write) objMyFile.Write(objMyData, 0, objMyData.Length) Unable to cast object of type 'System.String' to type 'System.Byte[]' in vb.net WHERE Document is a column in table in sql2005 that has a varchar(max) dataype. I've tried converting it to 'Dim encoding As New System.Text.ASCIIEncoding() 'objMyData = encoding.GetBytes(objMyRow("Document")) but the resulting document has an ascii format. Thank you in advance.... Quote
Administrators PlausiblyDamp Posted November 27, 2009 Administrators Posted November 27, 2009 There are other encoding classes under System.Text you could use, System.Text.UnicodeEncoding or one of the System.Text.UTFxxEncoding classes instead. Alternatively you might try using a StreamWriter to write the strings directly to the file rather than handling the encoding yourself. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.