Click here to Skip to main content
15,895,841 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi ,
I am creating a code that can save Array of Byte from Resource to a file .
So I go to Solution explorer > Properties > Resource tab > and set Files (ctrl + 5 ) .

This is my code :
C#
byte[] picArray = System.IO.File.ReadAllBytes(Properties.Resources.File);

System.IO.File.WriteAllBytes(@"Path", picArray);



this code must Assign( Properties.Resources.File) to picArray , But it run with error "Illegal characters in path." in first line ,

what i can do to solve this problem ?
thanks in advance .
Posted
Comments
bowlturner 20-Dec-13 16:15pm    
Well what is your path? It looks like you are just sending 'Path' which I'm pretty sure isn't a valid one
MohammadSina Karvandi 20-Dec-13 16:25pm    
I Saved all of the Files in Properties.Resources ,,, so this a File path.

@"Path" is a path in my computer ... I write @"Path" for this question , it is correct in Original code
bowlturner 20-Dec-13 16:45pm    
one of us is missing some information. if you have code that's working display both and lets see what's different.
BillWoodruff 20-Dec-13 16:49pm    
See the code samples here:

http://stackoverflow.com/a/13064059

1 solution

The problem is that you are trying to read the file from the disk, using the data in your resources as the path to the file.

It doesn't "Assign( Properties.Resources.File) to picArray" it tries to use that info as as file path instead. Probably, you want this instead:
C#
byte[] picArray = (byte[])Properties.Resources.File;
System.IO.File.WriteAllBytes(@"Path", picArray);
 
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