WebClient.UploadFile 
Author Message
 WebClient.UploadFile

I'm having a terrible time getting this method to work. I keep getting
'access denied' errors on my own machine. That is, I'm trying to upload a
file to a share on //localhost, but it doesn't work.

I've tried using the IUSR account, my own account, anonymous, not anonymous.
I don't really know what I'm doing. Surely there's something obvious and
simple I'm doing wrong. Perhaps I have messed something up in my IIS
configuration, but I don't know what. Any help is much appreciated!

Here is the code I'm running; it's adapted from an example in the
documentation:

using System;
using System.Net;

namespace testWebClient
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 class WcApp
 {
  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   Console.WriteLine("Enter the local file name:");
   string sFilename = Console.ReadLine();

   Console.WriteLine("Enter the Web destination:");
   string sDestination = Console.ReadLine();

   Console.WriteLine("Enter the user name:");
   string sUserName = Console.ReadLine();

   Console.WriteLine("Enter the password:");
   string sPassword = Console.ReadLine();

   Console.WriteLine("Uploading {0} to {1}...", sFilename, sDestination);

   WebClient wc = new WebClient();
   byte[] abtResponse = null;
   try
   {
    wc.Credentials = new NetworkCredential(sUserName, sPassword);
     abtResponse = wc.UploadFile(sDestination, sFilename);
   }
   catch (WebException Err)
   {
    Console.WriteLine(Err.Message);
    Console.ReadLine();
    return;
   }
   Console.WriteLine(System.Text.Encoding.ASCII.GetString(abtResponse));
   Console.ReadLine();
  }
 }

Quote:
}

Adam


Wed, 06 Oct 2004 21:54:00 GMT  
 WebClient.UploadFile
have you checked the obvious?
such as that the directory your uploading to has rights for reading and
writing?


Quote:
> I'm having a terrible time getting this method to work. I keep getting
> 'access denied' errors on my own machine. That is, I'm trying to upload a
> file to a share on //localhost, but it doesn't work.

> I've tried using the IUSR account, my own account, anonymous, not
anonymous.
> I don't really know what I'm doing. Surely there's something obvious and
> simple I'm doing wrong. Perhaps I have messed something up in my IIS
> configuration, but I don't know what. Any help is much appreciated!

> Here is the code I'm running; it's adapted from an example in the
> documentation:

> using System;
> using System.Net;

> namespace testWebClient
> {
>  /// <summary>
>  /// Summary description for Class1.
>  /// </summary>
>  class WcApp
>  {
>   /// <summary>
>   /// The main entry point for the application.
>   /// </summary>
>   [STAThread]
>   static void Main(string[] args)
>   {
>    Console.WriteLine("Enter the local file name:");
>    string sFilename = Console.ReadLine();

>    Console.WriteLine("Enter the Web destination:");
>    string sDestination = Console.ReadLine();

>    Console.WriteLine("Enter the user name:");
>    string sUserName = Console.ReadLine();

>    Console.WriteLine("Enter the password:");
>    string sPassword = Console.ReadLine();

>    Console.WriteLine("Uploading {0} to {1}...", sFilename, sDestination);

>    WebClient wc = new WebClient();
>    byte[] abtResponse = null;
>    try
>    {
>     wc.Credentials = new NetworkCredential(sUserName, sPassword);
>      abtResponse = wc.UploadFile(sDestination, sFilename);
>    }
>    catch (WebException Err)
>    {
>     Console.WriteLine(Err.Message);
>     Console.ReadLine();
>     return;
>    }
>    Console.WriteLine(System.Text.Encoding.ASCII.GetString(abtResponse));
>    Console.ReadLine();
>   }
>  }
> }

> Adam



Thu, 07 Oct 2004 09:43:52 GMT  
 WebClient.UploadFile
It does, I think. I created a directory called \\localhost\adam2\upload in
IIS (on WinXP pro). Then I displayed properties of the upload directory and
allowed read, write access, and dir browse permission with anonymous access
enabled.

To my (limited) knowledge, this is all I should have to do, but it still
doesn't work.


Quote:
> have you checked the obvious?
> such as that the directory your uploading to has rights for reading and
> writing?



> > I'm having a terrible time getting this method to work. I keep getting
> > 'access denied' errors on my own machine. That is, I'm trying to upload
a
> > file to a share on //localhost, but it doesn't work.

> > I've tried using the IUSR account, my own account, anonymous, not
> anonymous.
> > I don't really know what I'm doing. Surely there's something obvious and
> > simple I'm doing wrong. Perhaps I have messed something up in my IIS
> > configuration, but I don't know what. Any help is much appreciated!

> > Here is the code I'm running; it's adapted from an example in the
> > documentation:

> > using System;
> > using System.Net;

> > namespace testWebClient
> > {
> >  /// <summary>
> >  /// Summary description for Class1.
> >  /// </summary>
> >  class WcApp
> >  {
> >   /// <summary>
> >   /// The main entry point for the application.
> >   /// </summary>
> >   [STAThread]
> >   static void Main(string[] args)
> >   {
> >    Console.WriteLine("Enter the local file name:");
> >    string sFilename = Console.ReadLine();

> >    Console.WriteLine("Enter the Web destination:");
> >    string sDestination = Console.ReadLine();

> >    Console.WriteLine("Enter the user name:");
> >    string sUserName = Console.ReadLine();

> >    Console.WriteLine("Enter the password:");
> >    string sPassword = Console.ReadLine();

> >    Console.WriteLine("Uploading {0} to {1}...", sFilename,
sDestination);

> >    WebClient wc = new WebClient();
> >    byte[] abtResponse = null;
> >    try
> >    {
> >     wc.Credentials = new NetworkCredential(sUserName, sPassword);
> >      abtResponse = wc.UploadFile(sDestination, sFilename);
> >    }
> >    catch (WebException Err)
> >    {
> >     Console.WriteLine(Err.Message);
> >     Console.ReadLine();
> >     return;
> >    }
> >    Console.WriteLine(System.Text.Encoding.ASCII.GetString(abtResponse));
> >    Console.ReadLine();
> >   }
> >  }
> > }

> > Adam



Fri, 08 Oct 2004 08:04:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. WebClient.UploadFile

2. NEWBIE: Need help with WebClient.UploadFile()

3. Trouble with WebClient.UploadFile()

4. Microsoft's UploadFile method sucks!

5. UploadFile method

6. WebClient - which URL did I download?

7. Download file via WebClient

8. WebClient and word documents

9. WebClient Class can do that?

10. System.Net.WebClient.OpenRead question...

11. WebClient - What am I missing?

12. WebClient request performance problems

 

 
Powered by phpBB® Forum Software