Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8648453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:19:01+00:00 2026-06-12T13:19:01+00:00

C#’s uploadData method doesn’t encode the data that is being sent. So, if I

  • 0

C#’s uploadData method doesn’t encode the data that is being sent. So, if I send a file over (after converting it into bytes) using this method, and the receiving side is looking for a multiform/form-data post, then it will obviously not work. Will adding a header like :

WebClient c = new WebClient();
c.Headers.Add("Content-Type", "multipart/form-data");

make it send the data encrypted as multiform, or will the data be still not encrypted (and hence unparseable by servers expecting multiform data) ?

Note that I can’t use WebClient's uploadFile, as I don’t have permission to get the file path location on the client side (I just have a stream, that I can convert to bytes)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:19:02+00:00Added an answer on June 12, 2026 at 1:19 pm

    Why don’t you use UploadFile of WebClient over https if you want it to be secure? and that will automatically take care of adding multipart/form-data.

    Example using UploadFile

    http://msdn.microsoft.com/en-us/library/36s52zhs.aspx

    And one more thing, encoding and encrypting are 2 different things.

    Edit:

    You should probably tag your question as Silverlight if you you are using WebClient in your WebClient project. Anyways, WebClient class in SL doesn’t have any UploadData method. See this for more info:

    http://msdn.microsoft.com/en-us/library/system.net.webclient%28v=vs.95%29.aspx

    Anyways, here is the working solution to your problem:

    In your button click, have this code:

    OpenFileDialog dialog = new OpenFileDialog();
                bool? retVal = dialog.ShowDialog();
                if (retVal.HasValue && retVal == true)
                {
                    using (Stream stream = dialog.File.OpenRead())
                    {
                        MemoryStream memoryStream = new MemoryStream();
                        stream.CopyTo(memoryStream);
                        WebClient webClient = new WebClient();
                        webClient.Headers["Content-type"] = "multipart/form-data; boundary=---------------------------" + _boundaryNo;
                        webClient.OpenWriteAsync(new Uri("http://localhost:1463/Home/File", UriKind.Absolute), "POST", new { Stream = memoryStream, FileName = dialog.File.Name });
                        webClient.OpenWriteCompleted += new OpenWriteCompletedEventHandler(webClient_OpenWriteCompleted);
                    }
                } 
    

    and the event itself:

    void webClient_OpenWriteCompleted(object sender, OpenWriteCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    Stream responseStream = e.Result as Stream;                
                    dynamic obj = e.UserState;
                    MemoryStream memoryStream = obj.Stream as MemoryStream;
                    string fileName = obj.FileName;
                    if (responseStream != null && memoryStream != null)
                    {
                        string headerTemplate = string.Format("-----------------------------{0}\r\n", _boundaryNo);
    
                        memoryStream.Position = 0;
                        byte[] byteArr = memoryStream.ToArray();
                        string data = headerTemplate + string.Format("Content-Disposition: form-data; name=\"pic\"; filename=\"{0}\"\r\nContent-Type: application/octet-stream\r\n\r\n", fileName);
                        byte[] header = Encoding.UTF8.GetBytes(data);
                        responseStream.Write(header, 0, header.Length);
    
                        responseStream.Write(byteArr, 0, byteArr.Length);
                        header = Encoding.UTF8.GetBytes("\r\n");
                        responseStream.Write(byteArr, 0, byteArr.Length);
    
                        byte[] trailer = System.Text.Encoding.UTF8.GetBytes(string.Format("-----------------------------{0}--\r\n", _boundaryNo));
                        responseStream.Write(trailer, 0, trailer.Length);                    
                    }
                    memoryStream.Close();
                    responseStream.Close();
                }
            }
    

    where _boundaryNo is private string _boundaryNo = DateTime.Now.Ticks.ToString("x");

    I had it working with Asp.Net MVC 4 and Silverlight 5.

    Good luck 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.