Problems with WebClient.UploadFile

D

David W

I am trying to upload a file from a user's system to my web server. I
found code using the WebClient.UploadFile method. However, the
uploaded file is from the server's hard drive not the user's system.
I don't want to use the input file method (as this will force the user
to do unnessecary browsing and I know where the file will be:
c:\test.txt for example). I am sure that I am just missing something
simple. However, I can not figure out what it is. I keep getting the
file from the server moved to the new location as opposed to the file
from the user's system.

Any suggestions??

Below is the current version of the code:

---------------------------------------------
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Net"%>
<%@ Import NameSpace="System.Web"%>

<Script language="C#" runat=server>

public void UploadFile( Object s, EventArgs e )
{
//Create the GUID used for the Uploaded File
Guid strGuid = Guid.NewGuid();

//The GUID is used for the Destination
string strUploadURI = "http://localhost/upload.aspx?g=" +
strGuid.ToString("N");

WebClient myWebClient = new WebClient();
myWebClient.UploadFile(strUploadURI, "POST", "c:\\test.txt");

info.InnerHtml = "<p>FILE UPLOADED</p>";
}
</script>

<html>
<title>TEST</title>
<body>

<form runat="server">

<input type="submit" value="Click ME" OnServerClick="UploadFile"
Runat="Server">

<span id="info" Runat="Server" />

</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top