Last active
January 4, 2016 05:59
-
-
Save yannvery/8578948 to your computer and use it in GitHub Desktop.
Upload file web method with c#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public bool UploadFile(string FileName, byte[] buffer, long Offset) | |
| { | |
| bool retVal = false; | |
| try | |
| { | |
| // setting the file location to be saved in the server. | |
| // reading from the web.config file | |
| string FilePath = | |
| //Path.Combine(ConfigurationManager.AppSettings["upload_path"], FileName); | |
| //WebConfigurationManager.AppSettings["PFUserName"].ToString() | |
| Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath | |
| ("~/TransientStorage/"), FileName); | |
| ; | |
| if (Offset == 0) // new file, create an empty file | |
| File.Create(FilePath).Close(); | |
| // open a file stream and write the buffer. | |
| // Don't open with FileMode.Append because the transfer may wish to | |
| // start a different point | |
| using (FileStream fs = new FileStream(FilePath, FileMode.Open, | |
| FileAccess.ReadWrite, FileShare.Read)) | |
| { | |
| fs.Seek(Offset, SeekOrigin.Begin); | |
| fs.Write(buffer, 0, buffer.Length); | |
| } | |
| retVal = true; | |
| } | |
| catch (Exception e) | |
| { | |
| //sending error to an email id | |
| } | |
| return retVal; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment