Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
An unhandled exception of type 'System.InvalidCastException' occurred in SLA.exe

Additional information: Unable to cast object of type 'System.String' to type 'System.Byte[]'.


SLA.exe is my program. when i want to open files with my program it show me that error.
this is my code :

C#
byte[] FileData = (byte[])DS.Tables["FilelibF"].Rows[SelectedRow]["FileData"];

                String newfile = @"D:\Temp";
                DirectoryInfo l_dDirInfo = new DirectoryInfo(newfile);
                if (l_dDirInfo.Exists == false)
                {
                    Directory.CreateDirectory(newfile);
                }


what is wrong and how to fix it ?
Posted
Comments
Muhammad Idrees GS 26-Dec-15 9:13am    
Are you sure the following table field contains binary data?
DS.Tables["FilelibF"].Rows[SelectedRow]["FileData"]

It seems this field has simple string content and you are trying to convert string to byte[], causing this error.
brandon1999 26-Dec-15 9:35am    
thanks . fixed it.

1 solution

Answered only to remove from unanswered list: solved according to OP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900