Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following iphone code is used to upload file in server. And I want to convert this to c# so that I can it use it in my metro application.

CSS
NSString *urlString = [NSString stringWithFormat:@"http://ip address/win8/PNGUpload-xml.php?device=win8&UID=%@",appDelegate.UID];


NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];


NSString *boundary = @"---------------------------14737809831466499882746641449";


NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];


NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@.png\"\r\n",appDelegate.UID] dataUsingEncoding:NSUTF8StringEncoding]];

[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];


[body appendData:imageData];

[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];


// now lets make the connection to the web
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

NSLog(@"Returned: %@" ,returnString);
Posted

1 solution

You don't need to convert anything...
See this: how to download a file from internet[^]. It should works with metro application.

BTW: Thank you Sergey for your Great Job!

[EDIT]
Downloading and Uploading means almost the same but in different direction ;)

Start here: QuickStart: Uploading a file[^]
Upload Captured Image in Metro Style using C#[^]

[/EDIT]
 
Share this answer
 
v3
Comments
mayankkarki 7-Mar-13 4:25am    
Thanks for reply but I asked question to upload a file.
Maciej Los 7-Mar-13 5:51am    
See my answer after update ;)
mayankkarki 7-Mar-13 6:36am    
Thanks using background uploader is awesome
Maciej Los 7-Mar-13 8:47am    
You're welcome.
Does my solution was helpful? If yes, please, rate it.

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