Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Uploading with webclient

Posted on 2004-10-07
13
Medium Priority
?
1,292 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
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!

 
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

636 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