• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1902
  • Last Modified:

Winforms WebClient.UploadFile() error (System.NotSupportedException)

I am simply trying to upload a file to a URL and the following error message is generated:

System.Net.WebException: An exception occurred during a WebClient request. ---> System.NotSupportedException: The stream does not support concurrent IO read or write operations.
   at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
   at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.WebClient.UploadBitsState.WriteBytes()
   at System.Net.WebClient.UploadBits(WebRequest request, Stream readStream, Byte[] buffer, Byte[] header, Byte[] footer, CompletionDelegate completionDelegate, AsyncOperation asyncOp)
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
   --- End of inner exception stack trace ---
   at System.Net.WebClient.UploadFile(Uri address, String method, String fileName)
   at BREN_iTropics_001.frmUnifiedXML.simpleDataUpload() in frmUnifiedXML.cs:line 61

The offending line is:

byte[] Byte_response = wClient.UploadFile(url, "POST",filename);

can someone see the problem?
private void simpleDataUpload()
{
    try
    {
        Uri url = new Uri(this.txtFTPServer.Text);
        WebClient wClient = new WebClient();
        NetworkCredential nc = new NetworkCredential("login", "pass");
        wClient.Credentials = nc;
        byte[] Byte_response = wClient.UploadFile(url, "POST", filename);

        wClient.UploadProgressChanged += new UploadProgressChangedEventHandler(wClient_UploadProgressChanged);
        wClient.UploadFileCompleted += new UploadFileCompletedEventHandler(wClient_UploadFileCompleted);

        if (Byte_response != null)
        {
            this.txtMsg.Text += System.Text.Encoding.ASCII.GetString(Byte_response);
        }
    }
    catch (Exception ex)
    {
        this.txtMsg.Text += ex.ToString() + Environment.NewLine;
    }
}

void wClient_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
    this.txtLastResult.Text = "Sent:" + e.BytesSent.ToString() + "  Total:"
                        + e.TotalBytesToSend.ToString() + "   Progress:"
                        + e.ProgressPercentage.ToString() + "%";
}

Open in new window

0
conrad2010
Asked:
conrad2010
  • 2
1 Solution
 
GewgalaCommented:
Are you sure you have correct credentials?
0
 
GewgalaCommented:
And if you have correct credentials, are you sure you have sufficient privileges to perform your upload with them?
0
 
bkokxCommented:
Problem might be in your "POST" argument.
POST is used for HTTP while for FTP this should be STOR.
These defaults are chosen by the function if you do not specify the argument.
0
 
conrad2010Author Commented:
yes, the credentials are correct and I have permission to store (tested it in a browser upload version)

-C
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now