Solved

Uploading with webclient

Posted on 2004-10-07
13
1,220 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
  • 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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 500 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now