Webclient produce boundary ----WebKitFormBoundary8huFCK1rAfUxxul6

193 Views Asked by At

I have a WebClient and I am trying to upload a file programmatically in C#.

While uploading the file using the real webform I get the following problem:

------WebKitFormBoundary8huFCK1rAfUxxul6
Content-Disposition: form-data; name="__EVENTTARGET"


------WebKitFormBoundary8huFCK1rAfUxxul6
Content-Disposition: form-data; name="__EVENTARGUMENT"


------WebKitFormBoundary8huFCK1rAfUxxul6
Content-Disposition: form-data; name="__VIEWSTATE"

The code I am using to upload the file is as follows:

internal void UploadFile(System.IO.FileInfo cvFileInfo)
    {
        if (cvFileInfo.Exists == false)
            throw new FileNotFoundException("The Specified file was not found.");

//I know this part is wrong >
        var values = new NameValueCollection
        {
            { "Content-Disposition: form-data; name=\"__EVENTTARGET\""        , ""                  } ,
            { "Content-Disposition: form-data; name=\"__EVENTARGUMENT\""      , ""                  } ,
            { "Content-Disposition: form-data; name=\"__VIEWSTATE\""          , _viewstate          } ,
            { "Content-Disposition: form-data; name=\"__VIEWSTATE\""          , _viewstategenerator } ,
            { "Content-Disposition: form-data; name=\"__EVENTVALIDATION\""    , _eventvalidation    } ,
            { "Content-Disposition: form-data; name=\"ctl00$main$CVFile\"; filename=\"Kiran Randhawa - Curriculum vitae - Copy.docx\" Content-Type: application/octet-stream", Encoding.UTF8.GetString(File.ReadAllBytes(cvFileInfo.FullName)) },
            { "Content-Disposition: form-data; name=\"ctl00$main$btnUpload\"" , "Upload Now"         } ,
        };

        var returnedBytes = client.UploadValues(_uploadCVUrl, values);
        var returnedString = System.Text.Encoding.UTF8.GetString(returnedBytes);

        if (returnedString != null)
        {

        }
    }

How do I fix this in such a way that it produces the desired packet output.

Many Thanks, Kiran

0

There are 0 best solutions below