Save file from byte array on servermap path

a 夏天 提交于 2019-12-07 13:05:44

It could be a permissions issue... The account ASP.net runs under has to have write privileges to the target directory.

Another "not answer", but maybe helpful to rule some stuff out. I tried

  byte[] data = new byte[] { 12, 14, 63, 45, 3 };

  System.IO.FileStream file = System.IO.File.Create(HttpContext.Current.Server.MapPath(".\\imageLibrary\\test.pdf "));

  file.Write(data, 0, data.Length);
  file.Close();

and it worked fine (test.pdf was created). I had thought that the space at the end of your file path could be causing problems but that's not it.

Are you sure you haven't enclosed this block in a try{}catch{} block that might be swallowing a path or permissions error? Have you tried setting a breakpoint on the file.Close() line to make sure it gets that far?

Server.MapPath(".\\TmpImages\\"+hfFileName+".pdf ")

Are you sure the path is what you expect it to be? If you're sure you're not getting an exception (i.e. permissions), then I would recommend debugging and seeing what value the call to Server.MapPath returns.

It's possible that the file is being written out, but to a different location than you expected.

"If [the argument to MapPath] doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed." http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!