Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Forked from Benrnz/FileUploadAspNet.cs
Last active December 30, 2015 04:09
Show Gist options
  • Save csharpforevermore/7774504 to your computer and use it in GitHub Desktop.
Save csharpforevermore/7774504 to your computer and use it in GitHub Desktop.
Uploads a file to the server and save it to disk. (INCOMPLETE)
public static bool UploadToServer(string pathToFile)
{
bool failure = false;
if (!FileUpload1.FileName.ToLowerInvariant().EndsWith(".xml")) {
failure = true;
}
StreamReader reader = new StreamReader(FileUpload1.FileContent);
string xmlContent = reader.ReadToEnd();
if (!xmlContent.TrimStart().StartsWith("<?xml")) {
failure = true;
}
if (!failure) {
Label1.Text = "Only xml files can be uploaded.";
} else {
FileUpload1.SaveAs(this.Server.MapPath("TestData.xml"));
Label1.Text = "File Uploaded: " + FileUpload1.FileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment