将字节数组中的文件保存在servermap路径上 [英] Save file from byte array on servermap path

查看:95
本文介绍了将字节数组中的文件保存在servermap路径上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从字节数组中保存PDF文件,并希望将该文件保存在服务器映射路径位置.

I Want to save a PDF file from a byte array and want to save that file on my server map path location.

下面是我的代码段.它没有任何错误,也没有保存文件.如果错误,欢迎您改正我的语法,也可以参考其他代码段来帮助我.

Below is my code snippet. It's giving no errors nor saving the file. You are welcome to correct my syntax if it is wrong or help me by referring other code snippets.

byte[] data = (byte[])listDataset.Tables[0].Rows[0][0];

System.IO.FileStream file = System.IO.File.Create(Server.MapPath(".\\TmpImages\\"+hfFileName+".pdf "));

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

推荐答案

另一个不回答",但可能有助于排除某些问题.我尝试过

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();

,它运行良好(创建了test.pdf).我以为文件路径末尾的空格可能会引起问题,但不是那样.

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.

您确定没有将try_} catch {}块中的这个块包含在路径或权限错误中吗?您是否尝试过在file.Close()行上设置断点以确保其达到目标位置?

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?

这篇关于将字节数组中的文件保存在servermap路径上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆