HttpPostedFile file = Request.Files["myFile"]; if(file != null && file.ContentLength > 0) { string fileName = Path.GetFileName(file.FileName); string fileFolderPath = Server.MapPath("~/UploadedFiles/"); string filePath = Path.Combine(fileFolderPath, fileName); file.SaveAs(filePath); }
HttpPostedFile file = Request.Files["myFile"]; if(file != null && file.ContentLength > 0) { byte[] fileContents = new byte[file.ContentLength]; file.InputStream.Read(fileContents, 0, file.ContentLength); string fileName = file.FileName; string fileType = file.ContentType; //save fileContents, fileName, and fileType to database }This code example checks for an uploaded file with a key of "myFile", reads the file's contents into a byte array, gets the file name and content type, and then saves them to a database. The package library for HttpPostedFile is part of the .NET Framework and is included in the System.Web.dll assembly.