?
Solved

Uploading with webclient

Posted on 2004-10-07
13
Medium Priority
?
1,277 Views
Last Modified: 2008-01-09
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
Comment
Question by:FLUXWIRE
[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
  • 7
  • 6
13 Comments
 

Author Comment

by:FLUXWIRE
ID: 12251409
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
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12254166
Some code may help.
0
 

Author Comment

by:FLUXWIRE
ID: 12256966
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:AvonWyss
ID: 12256979
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
 

Author Comment

by:FLUXWIRE
ID: 12257092
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
 

Author Comment

by:FLUXWIRE
ID: 12257121
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
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12257127
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
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12257128
Are we talking about a web application (run over the browser) or a standalone application (.EXE file)?
0
 

Author Comment

by:FLUXWIRE
ID: 12257166
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
 

Author Comment

by:FLUXWIRE
ID: 12257168
i will be back in 45 minuts!
thx
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 2000 total points
ID: 12257230
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
 

Author Comment

by:FLUXWIRE
ID: 12257387
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
 
LVL 14

Expert Comment

by:AvonWyss
ID: 12257405
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

801 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