Guest User

Untitled

a guest
Jun 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. private void UploadFile(string filename)
  2. {
  3. try
  4. {
  5. PeopleMatrixService peopleMetrixService = new PeopleMatrixService();
  6.  
  7. String strFile = System.IO.Path.GetFileName(filename);
  8. // TestUploader.Uploader.FileUploader srv = new TestUploader.Uploader.FileUploader();
  9. FileInfo fInfo = new FileInfo(filename);
  10. long numBytes = fInfo.Length;
  11. double dLen = Convert.ToDouble(fInfo.Length / 10000000);
  12. if (dLen < 8)
  13. {
  14. FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
  15. BinaryReader br = new BinaryReader(fStream);
  16. byte[] data = br.ReadBytes((int)numBytes);
  17. br.Close();
  18. string sTmp = peopleMetrixService.UploadFile(data, strFile);
  19. fStream.Close();
  20. fStream.Dispose();
  21. MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
  22. }
  23. else
  24. {
  25. MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
  26. }
  27. }
  28. catch (Exception ex)
  29. {
  30. MessageBox.Show(ex.Message.ToString(), "Upload Error");
  31. }
  32. }
  33.  
  34. [WebMethod]
  35. public string UploadFile(byte[] f, string fileName)
  36. {
  37. try
  38. {
  39. MemoryStream ms = new MemoryStream(f);
  40. FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath("~/Response Attachments/") + fileName, FileMode.Create);
  41. //FileStream fs = new FileStream(Server.MapPath("~/Response Attachments/") + fileName, FileMode.Create);
  42. ms.WriteTo(fs);
  43. ms.Close();
  44. fs.Close();
  45. fs.Dispose();
  46. return "OK";
  47. }
  48. catch (Exception ex)
  49. {
  50. return ex.Message.ToString();
  51. }
  52. }
  53.  
  54. <configuration>
  55. <system.web>
  56. <httpRuntime executionTimeout="300" maxRequestLength="20480" />
  57. </system.web>
  58. </configuration>
  59.  
  60. <system.web>
  61. <httpRuntime executionTimeout="360" maxRequestLength="100000" />
  62.  
  63. C:WindowsSystem32inetsrv>appcmd set config "[IISWebsitename]" -section:requestFiltering -requestLimits.maxAllowedContentLength:100000000 -commitpath:apphost
Add Comment
Please, Sign In to add comment