Click here to Skip to main content
15,893,381 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionRemote File Upload Through ASP .Net page Pin
Vodstok11-Mar-13 5:54
Vodstok11-Mar-13 5:54 
QuestionRe: Remote File Upload Through ASP .Net page Pin
jkirkerx11-Mar-13 8:26
professionaljkirkerx11-Mar-13 8:26 
AnswerRe: Remote File Upload Through ASP .Net page Pin
Vodstok11-Mar-13 8:31
Vodstok11-Mar-13 8:31 
GeneralRe: Remote File Upload Through ASP .Net page Pin
jkirkerx11-Mar-13 9:56
professionaljkirkerx11-Mar-13 9:56 
AnswerRe: Remote File Upload Through ASP .Net page Pin
Richard Deeming11-Mar-13 9:13
mveRichard Deeming11-Mar-13 9:13 
GeneralRe: Remote File Upload Through ASP .Net page Pin
Vodstok11-Mar-13 9:26
Vodstok11-Mar-13 9:26 
GeneralRe: Remote File Upload Through ASP .Net page Pin
Vodstok12-Mar-13 4:20
Vodstok12-Mar-13 4:20 
GeneralRe: Remote File Upload Through ASP .Net page Pin
Richard Deeming12-Mar-13 4:36
mveRichard Deeming12-Mar-13 4:36 
Based on a quick test I did last night, I came to the conclusion that the Name of each part needs to be enclosed in quotes:
C#
foreach (KeyValuePair<string, string> keyValuePair in values)
{
   content.Add(new StringContent(keyValuePair.Value), "\"" + keyValuePair.Key + "\"");
}

Without this, ASP.NET doesn't think there's a form present.
(I'm not sure if this is a bug in ASP.NET, a bug in the HttpClient implementation, or a misunderstanding on my part.)

You'll need to specify the name for the file content, which should be equal to the name of the FileUpload control on the target page.

I also found that if the FileName isn't enclosed in quotes, ASP.NET request validation rejects the request:
C#
ByteArrayContent fileContent = new ByteArrayContent(File.ReadAllBytes(fileName));
content.Add(fileContent, "\"nameOfTheFileUpload\"", "\"" + Path.GetFileName(fileName) + "\"");
// This overload of Add automatically creates the Content-Disposition header.


You're missing an await on the client.PostAsync line, but I presume that's just a typo.

You can also replace the ReadAsStream + Read + Encoding.ASCII.GetString block with a simple await response.Content.ReadAsStringAsync() call.

If all else fails, you can always trace the request with Fiddler[^].



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Remote File Upload Through ASP .Net page Pin
Vodstok12-Mar-13 5:13
Vodstok12-Mar-13 5:13 
GeneralRe: Remote File Upload Through ASP .Net page Pin
Vodstok14-Mar-13 4:27
Vodstok14-Mar-13 4:27 
QuestionASP.Net MVC 4? Pin
silentspeaker11-Mar-13 3:38
silentspeaker11-Mar-13 3:38 
AnswerRe: ASP.Net MVC 4? Pin
Sandeep Mewara11-Mar-13 4:16
mveSandeep Mewara11-Mar-13 4:16 
AnswerRe: ASP.Net MVC 4? Pin
Thomas Daniels11-Mar-13 8:40
mentorThomas Daniels11-Mar-13 8:40 
Questionrunat=server Pin
tiwal11-Mar-13 0:47
tiwal11-Mar-13 0:47 
AnswerRe: runat=server Pin
Deflinek11-Mar-13 4:24
Deflinek11-Mar-13 4:24 
AnswerRe: runat=server Pin
Sandeep Mewara11-Mar-13 4:26
mveSandeep Mewara11-Mar-13 4:26 
AnswerRe: runat=server Pin
jkirkerx11-Mar-13 9:06
professionaljkirkerx11-Mar-13 9:06 
Questionquery regarding session nature Pin
Tridip Bhattacharjee11-Mar-13 0:28
professionalTridip Bhattacharjee11-Mar-13 0:28 
AnswerRe: query regarding session nature Pin
Keith Barrow11-Mar-13 0:54
professionalKeith Barrow11-Mar-13 0:54 
GeneralRe: query regarding session nature Pin
Tridip Bhattacharjee11-Mar-13 1:07
professionalTridip Bhattacharjee11-Mar-13 1:07 
GeneralRe: query regarding session nature Pin
Keith Barrow11-Mar-13 1:22
professionalKeith Barrow11-Mar-13 1:22 
GeneralRe: query regarding session nature Pin
Tridip Bhattacharjee11-Mar-13 4:49
professionalTridip Bhattacharjee11-Mar-13 4:49 
GeneralRe: query regarding session nature Pin
Keith Barrow11-Mar-13 5:02
professionalKeith Barrow11-Mar-13 5:02 
QuestionNeed to crawl a Microsoft WebPage which live authenticated... Pin
Mutturaj Bali10-Mar-13 23:25
Mutturaj Bali10-Mar-13 23:25 
QuestionFind and replace string Pin
karthisomu10-Mar-13 20:41
karthisomu10-Mar-13 20:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.