views:

36

answers:

2

I have this snippet:

        protected void ProcessUpload(FileUpload upload)
        {
            if (upload.HasFile)
            {

                string fileName = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);
                if (File.Exists(fileName))
                    File.Delete(fileName);
                upload.SaveAs(fileName);
            }
        }

It is for ASP.NET, i want to run it in Windows Application. I get an error says FileUpload reference doesn't exist or so. FileUpload resides in System.Web.UI.WebControls which doesn't belong to Winforms family.

Please note that the file will be saved from desktop to remote file server (not ~/Uploads).

What should i do? What are the alternatives.

A: 

You would use My.Computer.Network.UploadFile() in a VB.NET app. The How-To article is here.

Hans Passant
Thanks! I will check it out. By the way, the file will be saved to a remote file server
A: 

What you are asking makes little sense. The FileUpload class handles a file that has been uploaded from a web page to a server, for processing on the server. If you are on a desktop app, the whole concept is removed: why would you upload a file from the desktop to the desktop?

If you want to copy a file, use File.Copy.

If you could give us some more context for how the user is supplying a file, we can be more specific with our answers.

Hope that helps: please post more information so we can get the details worked out.

Kieren Johnstone
You are right, i actually want to upload a file from desktop toa file server (ftp or so). The code i posted above is just a sample.