?
Solved

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

Posted on 2010-08-13
4
Medium Priority
?
1,867 Views
Last Modified: 2013-11-26
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
Comment
Question by:conrad2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 7

Expert Comment

by:Gewgala
ID: 33434698
Are you sure you have correct credentials?
0
 
LVL 7

Expert Comment

by:Gewgala
ID: 33434701
And if you have correct credentials, are you sure you have sufficient privileges to perform your upload with them?
0
 
LVL 3

Accepted Solution

by:
bkokx earned 2000 total points
ID: 33435351
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
 

Author Comment

by:conrad2010
ID: 33438406
yes, the credentials are correct and I have permission to store (tested it in a browser upload version)

-C
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question