Solved

Uploading with webclient

Posted on 2004-10-07
13
1,237 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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