Problems with System.Net.WebClient

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have a program that excutes the following code:

DirectoryInfo diretorio = new DirectoryInfo(@"C:\teste");
FileInfo[] arquivos = diretorio.GetFiles("*.xml");

for(int contador=0;contador<arquivos.Length;contador++)
{
lblMensagem.Text = "Uploading files... ";

ws.UploadFile("http://www.meusite.com.br/uploader.aspx","POST",arquivos[contador].FullName);
}

lblMensagem.Text = "Success!";

As you can see i've got a webpage that receives those files and saves on the
apropriate directory.

This code works when I'm running it on my machine. When I specify the link
to http://localhost/meusite/uploader.aspx the files are uploaded with no
errors but when i change the link to http://www.meusite.com.br/uploader.aspx
the following error appears:

"The remote server returned an error: (500) Internal Server Error."

Can anybody help me?

Thanks
 
It looks to me like you have not set the appropiate permissions so that the
ASPNET worker process can save the files to the directory. Change the
settings in your browser so you don't get "friendly errors" so you can see
the actual error message.

I don't remember off the top of my head, but I believe you have to add the
ASPNET account to the folder you intend to upload the files to and give it
full rights. Don't take my word for it though, find an article about it
online, it is not hard, just search for something like ".NET cannot upload
file".

Good luck!
 
Thanks for your help Juan, but my problem isn't on the web site, i've some
other pages that uploads some files and they all work fine. The problem here
is with the Windows Forms that i've programmed to use the UploadFile method
from the System.Net.WebClient class.





--
Bruno


Madestro said:
It looks to me like you have not set the appropiate permissions so that the
ASPNET worker process can save the files to the directory. Change the
settings in your browser so you don't get "friendly errors" so you can see
the actual error message.

I don't remember off the top of my head, but I believe you have to add the
ASPNET account to the folder you intend to upload the files to and give it
full rights. Don't take my word for it though, find an article about it
online, it is not hard, just search for something like ".NET cannot upload
file".

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray


Bruno Otero said:
Hi!

I have a program that excutes the following code:

DirectoryInfo diretorio = new DirectoryInfo(@"C:\teste");
FileInfo[] arquivos = diretorio.GetFiles("*.xml");

for(int contador=0;contador<arquivos.Length;contador++)
{
lblMensagem.Text = "Uploading files... ";

ws.UploadFile("http://www.meusite.com.br/uploader.aspx","POST",arquivos[contador].FullName);
}

lblMensagem.Text = "Success!";

As you can see i've got a webpage that receives those files and saves on the
apropriate directory.

This code works when I'm running it on my machine. When I specify the link
to http://localhost/meusite/uploader.aspx the files are uploaded with no
errors but when i change the link to http://www.meusite.com.br/uploader.aspx
the following error appears:

"The remote server returned an error: (500) Internal Server Error."

Can anybody help me?

Thanks
 
Bruno,

Your problem IS on the web site. The error message you posted is a response
from the server. The 500 code means there is something wrong with the
application you are running on the server. That is why it says "Internal
server error." Trust me, the error is happening on the server side. You may
be getting an error on your application, but that is probably because the
WebClient did not get a valid response from the server.


--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray


Bruno Otero said:
Thanks for your help Juan, but my problem isn't on the web site, i've some
other pages that uploads some files and they all work fine. The problem here
is with the Windows Forms that i've programmed to use the UploadFile method
from the System.Net.WebClient class.





--
Bruno


Madestro said:
It looks to me like you have not set the appropiate permissions so that the
ASPNET worker process can save the files to the directory. Change the
settings in your browser so you don't get "friendly errors" so you can see
the actual error message.

I don't remember off the top of my head, but I believe you have to add the
ASPNET account to the folder you intend to upload the files to and give it
full rights. Don't take my word for it though, find an article about it
online, it is not hard, just search for something like ".NET cannot upload
file".

Good luck!

--
Juan Romero
-----------------------------------------
The successful person has the habit of doing the things failures don't like
to do.
E.M. Gray


Bruno Otero said:
Hi!

I have a program that excutes the following code:

DirectoryInfo diretorio = new DirectoryInfo(@"C:\teste");
FileInfo[] arquivos = diretorio.GetFiles("*.xml");

for(int contador=0;contador<arquivos.Length;contador++)
{
lblMensagem.Text = "Uploading files... ";

ws.UploadFile("http://www.meusite.com.br/uploader.aspx","POST",arquivos[contador].FullName);
}

lblMensagem.Text = "Success!";

As you can see i've got a webpage that receives those files and saves on the
apropriate directory.

This code works when I'm running it on my machine. When I specify the link
to http://localhost/meusite/uploader.aspx the files are uploaded with no
errors but when i change the link to http://www.meusite.com.br/uploader.aspx
the following error appears:

"The remote server returned an error: (500) Internal Server Error."

Can anybody help me?

Thanks
 
Back
Top