Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1322
  • Last Modified:

Uploading with webclient

Hi!
Im using the webclient.uploadfile to send files to a server. If i use this control in my machine works fine. if i try to send to my server (in the same net) i got an :

"An exception occurred during a WebClient request. "

any idea?

env: vs2003 c#
0
FLUXWIRE
Asked:
FLUXWIRE
  • 7
  • 6
1 Solution
 
FLUXWIREAuthor Commented:
An information.
The problem is with the local file. Looks like the component is searching the local file in the server.
It do not find the file specified to upload. But the file is there.
0
 
AvonWyssCommented:
Some code may help.
0
 
FLUXWIREAuthor Commented:
Ok. here we go!

            WebClient myClient = new WebClient();
            NetworkCredential myCred = new NetworkCredential("count","password","domain") ;
// the account used belongs to domain admin, domain users and later the administrators

                  try
                  {

                        CredentialCache myCache = new CredentialCache();
                        myCache.Add(new Uri(theUri),"Basic",myCred );
                        myClient.Credentials = myCache;
                        byte[] resp = myClient.UploadFile("http://server/page.aspx?folder=foldername","POST", @"D:\folder1\folder2\picture.gif");
// well. i got the error when the code reaches this line above.
// if i run this in my localhost, works fine.

later, i tryied to use this:

FileStream file = new FileStream(@"D:\folder1\folder2\picture.gif",FileMode.Open);

and i got the same problem. same error.

the error that i got from debug watch is:
{"Could not find a part of the path \"C:\\ccc\\imagem4.JPG\"." } for example                              
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
AvonWyssCommented:
It seems that you don't have the file you're trying to upload. since you wrote that "FileStream file = new FileStream(@"D:\folder1\folder2\picture.gif",FileMode.Open);" also fails, this means that the file does not exist on the machine where you run the application.
0
 
FLUXWIREAuthor Commented:
Yeah! this is the first option, but...
im getting this file from the Freetextbox component. then the file exists!
i browse my local machine to get the file.
and believe me. i know that the file exists and is there

but, i agree that the problem is not a server problem. is local. i have no idea about it.
seems something with the SO. (w2k3). But i can reproduce the problem in other network.
thx in advance!
0
 
FLUXWIREAuthor Commented:
FYI
i create the same file in the server and now i got this
{"Access to the path \"C:\\ccc\\imagem2.JPG\" is denied." }
well. looks that the system is looking for this files in the server and not in the local machine.
why?
0
 
AvonWyssCommented:
Is your application running with full trust? Because if it isn't, you wouldn't have access to the file. But in this case, you should get an UnauthorizedAccessException rather than a FileNotFoundException (which I guess you're getting because of the message you posted: could not find a part of the path...).

Note that it does make a difference if you run an application from a network shate or drive or if it is being run from the local disk. Try copying the app to your local disk and see if it works then.
0
 
AvonWyssCommented:
Are we talking about a web application (run over the browser) or a standalone application (.EXE file)?
0
 
FLUXWIREAuthor Commented:
a web application.
this is happening in the page where i build messages to be sent throught e-mail.
i built the message with the freetextbox component and upload all files referenced by the
message to the server. In this moment, i change all D:\... by http://server...

btw. if i run the application in the localhost, works, because the server and the client wil be the same. and the file is there. but if i run the app from the server, the file referenced by the client is not in the server then i got the error. but this is the function of the webclient uploadfile isnt? get the file in the local machine and upload it to the server.
thx in advance!
0
 
FLUXWIREAuthor Commented:
i will be back in 45 minuts!
thx
0
 
AvonWyssCommented:
You're right about the function of uploadfile. BUT you're forgetting that the web application wil actually run on the server and not on the local machine! The local machine is nothing but an interface, it does NOT compute any of the code you wrote, this is all done by and on the server (the only exception are things like javascript and applets, but in your case, everything is run on the server). Therefore, you cannot upload the file like this. You'd need to use the HTML file upload to accomplish a file transfer from the local file system to the server.
0
 
FLUXWIREAuthor Commented:
well! ok. i understand!
i need to talk about the html file upload and my problem. what can i do? close this and open another?
0
 
AvonWyssCommented:
I can give you this as a starter:
http://www.c-sharpcenter.com/asp.net/FileUpload.htm

If that doesn't solve your problem, it's probably best to open a new question.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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