System.Diagnostics.Process.Start()不在Web服务器工作 [英] System.Diagnostics.Process.Start() doesn't work in the web server
问题描述
我有一个C#asp.net web页面从MySQL数据库中读取PDF文件(它保存为LONGBLOB格式),然后打开它。它工作在我的本地主机;页面读取数据库的文件并打开Acrobat Reader软件,但它并没有在测试服务器上的工作后,我部署的页面。 Acrobat Reader的不开,我没有看到acroRd32.exe在taskmgr经理。我觉得这是权限问题,因为我使用的Process.Start(),它可能不允许在服务器上,但我没有看到错误消息。如果有权限需要在服务器完成;任何人都可以亲切地指向我的方向?
感谢你。
这里是我的code:
MySqlDataReader将读卡器= NULL;
connection.Open();
的MySqlCommand命令=新的MySqlCommand(选择图片,FILE_TYPE,FILE_NAME从表在哪里ImageID =+ ImageID,连接);
读者= Command.ExecuteReader却();
如果(Reader.Read())
{
byte []的缓冲区=(byte []的)阅读器[形象];
System.IO.MemoryStream流1 =新System.IO.MemoryStream(缓冲,真正的);
stream1.Write(缓冲液,0,buffer.Length);
字符串文件名=读卡器[FILE_NAME]的ToString()。
字符串目录名称=C:\\ thefolder \\;
如果(!Directory.Exists(目录名))
{
//如果没有则创建
Directory.CreateDirectory(目录名);
}
如果(File.Exists(目录名+文件名))
File.Delete(目录名+文件名);
Directory.CreateDirectory(Path.GetDirectoryName(阅读器[FILE_NAME]的ToString()));
使用(流文件= File.Create(目录名+文件名))
{
file.Write(缓冲液,0,buffer.Length);
}
工艺过程=新工艺();
process.StartInfo.FileName =AcroRd32.exe;
的Process.Start();
}
感谢您的帮助,我能够通过响应发送PDF内容。这里是code
//处理程序=新的Process();
//process.StartInfo.FileName =AcroRd32.exe;
//process.Start();
Response.ClearHeaders();
Response.ContentType =应用程序/ PDF格式;
Response.Clear();
Response.AppendHeader(内容处置,附件);
Response.TransmitFile(目录名+文件名);
到Response.End();
您的C#code运行服务器上。
因此,的Process.Start
启动该服务器上的一个过程,而不是你的电脑。
这是根本不可能的,您可以直接在客户端上启动一个进程。
不过,如果你所服务的PDF中的HTTP响应(用正确的内容类型
),浏览器会在PDF查看器中打开它。
I have a C# asp.net web page which reads PDF file from Mysql database (which stores as longblob format) and open it. It works in my Localhost; the page reads the file from database and open with acrobat reader but it doesn't work in the testing server after i deploy the page. The acrobat reader doesn't open and i don't see acroRd32.exe in the taskmgr manager. I feel it is permission issue because i use process.start() which may not allow in the server but i dont see error messages. If there are permissions needs to be done in server; can anyone kindly points me the direction?
Thank You.
Here are my code:
MySqlDataReader Reader = null;
connection.Open();
MySqlCommand command = new MySqlCommand("Select Image, File_Type, File_Name from table where ImageID = " + ImageID, connection);
Reader = command.ExecuteReader();
if (Reader.Read())
{
byte[] buffer = (byte[])Reader["Image"];
System.IO.MemoryStream stream1 = new System.IO.MemoryStream(buffer, true);
stream1.Write(buffer, 0, buffer.Length);
String fileName = Reader["File_Name"].ToString();
String dirName = "C:\\thefolder\\";
if (!Directory.Exists(dirName))
{
// if not then create
Directory.CreateDirectory(dirName);
}
if (File.Exists(dirName+fileName))
File.Delete(dirName + fileName);
Directory.CreateDirectory(Path.GetDirectoryName(Reader["File_Name"].ToString()));
using (Stream file = File.Create(dirName + fileName))
{
file.Write(buffer, 0, buffer.Length);
}
Process process = new Process();
process.StartInfo.FileName = "AcroRd32.exe";
process.Start();
}
Thanks for your help, i am able to send pdf content via response. Here is the code
//Process process = new Process();
//process.StartInfo.FileName = "AcroRd32.exe";
//process.Start();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment");
Response.TransmitFile(dirName + fileName);
Response.End();
Your C# code runs on the server.
Therefore, Process.Start
starts a process on the server, not your computer.
It is fundamentally impossible for you to start a process directly on the client.
However, if you serve the PDF in the HTTP response (with the correct Content-Type
), the browser will open it in a PDF viewer.
这篇关于System.Diagnostics.Process.Start()不在Web服务器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!