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:
i am working on windows application which converts the file into bytes and post this converted bytes to the url where i want to access these converted bytes and after accessing i want to convert it back to its origional form.....
here is the code of windows form .

C#
byte[] bytes = System.IO.File.ReadAllBytes("E:\\Asim Pics\\At Home\\DSC_0000084.jpg");

           //System.IO.File.WriteAllBytes("E:\\asim.jpg", bytes);
           string url = "http://localhost:55937/binary-conversion/frm-conversion.aspx? q=" + bytes + "";
           //for hitting a specific url i am using this line
           System.Diagnostics.Process.Start(url);

and in aspx page i m using this code to access that file which i posted from windows form ....

C#
<pre lang="cs">string file =  Request.QueryString["q"];

       byte[] asdf = Convert.ToByte(file);

       System.IO.File.WriteAllBytes(@"E:\usman.jpg", asdf);

but i m getting an error when i try to convert this file to the bytes.... is this poosible that we transfer a file through url hitting and then access it from aspx pages and work on it ?????
Posted
Updated 12-Sep-13 0:56am
v3
Comments
thatraja 12-Sep-13 7:05am    
what's the error? always mention the error message to get quick response atleast normal response
Asim8748 12-Sep-13 7:17am    
error is that "cannot implicity convert string to bytes".
Asim8748 12-Sep-13 7:17am    
here is the error line
byte[] asdf = Convert.ToByte(file);

1 solution

You have to convert those bytes into a base64 string like follows:

C#
string url = "http://localhost:55937/binary-conversion/frm-conversion.aspx?q=" + Convert.ToBase64String(bytes);


then in your asp.net code you have to do this:

C#
byte[] asdf = Convert.FromBase64String(file);
 
Share this answer
 
Comments
Asim8748 12-Sep-13 7:42am    
when i m trying this code it gives me the following error ..

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: InString
and this error appears on aspx page .
Marc Gabrie 12-Sep-13 13:31pm    
validate that the variable "file" is not being null. Are you sure you used the same query string I posted here? Seeing your code it seems you have some space between "...? q=" which should not be there. Put a breakpoint in your aspx code and see what is going on...
Asim8748 13-Sep-13 6:36am    
there is no space between them. the "file" variable receive some bytes from URL query string but it discard the remaining bytes which I post from windows application. I think there is a issue in array size. after some time array get full and remaining data is discarded.
Marc Gabrie 13-Sep-13 8:10am    
keep in mind that query string length has a limit!!! each browser has different limits (just google about this topic to get those values) Maybe you should go for doing a HTTP POST like stating here http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data
Asim8748 13-Sep-13 8:15am    
I am also searched that from Google . but I didn't get any positive answer which can resolve my problem.

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