开发者

Where Can I Find FileUpload Class for Windows Application?

开发者 https://www.devze.com 2023-01-05 14:34 出处:网络
I have this snippet: protected void ProcessUpload(FileUpload upload) { if (upload.HasFile) { string fileName = Path.Combine(Server.MapPath(\"~/Uploads\"), upload.FileName);

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 开发者_Python百科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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消