kenom
kenom

Reputation: 31

how to upload files

How to upload files from ASP.NET web application to any web server(linux)..

Upvotes: 0

Views: 674

Answers (2)

p.campbell
p.campbell

Reputation: 100567

Take these steps as a general guideline:

  • include an ASP.NET server control for the user to upload the file
  • have its SaveAs path be a UNC path to a share on the remote server.

Here's more on the FileUpload ASP.NET Server Control at MSDN.

<asp:FileUpload ID="FileUpload1" runat="server" />

if (FileUpload1.HasFile)
{
    FileUpload1.SaveAs(@"\\server2\SomeShare\" + FileUpload1.FileName);
}

If you wanted the files to be saved first on your ASP.NET box:

  • save the file locally (something like c:\uploads\temp or what-have-you
  • at some interval or your chose event, move all files in that temp dir from server1 to server2.
  • use System.IO.File.Move
string[] files = System.IO.Directory.GetFiles(@"c:\uploads\temp");

foreach (string s in files)
{
    string fileName = System.IO.Path.GetFileName(s);
    string destFile = System.IO.Path.Combine(targetPath, fileName);
    System.IO.File.Copy(s, destFile);
}

Upvotes: 1

David
David

Reputation: 218827

If the Linux server in question exposes an FTP service, then here's a tutorial for accessing that in .NET. If FTP is not an option, then please specify what service the Linux server is exposing for file upload (Samba, NFS, etc.).

Upvotes: 0

Related Questions