我无法从C盘打开pdf文件。我尝试了以下编码 [英] I could not able to open pdf file from C drive. I tried below coding
问题描述
我无法从 c驱动器打开pdf文件。我试过以下编码
我尝试过的事情:
Dim lsfilename As String
Dim lsfilepath As String
hdnfilepath.Value = e.CommandArgument
Dim embed As String = < object data ={0}type =application / pdfwidth =500pxheight =600px>
embed + = < / object>
objdbconn.OpenConn()
msSQL =从dap_trn_tdocuments中选择document_gid,file_path,file_name,其中document_gid =' & hdnfilepath.Value& '
objOdbcDataReader = objdbconn.GetDataReader(msSQL)
如果objOdbcDataReader.HasRows = True那么
objOdbcDataReader.Read()
lsfilename = objOdbcDataReader.Item(file_name)。ToString
lsfilepath = objOdbcDataReader.Item(file_path)。ToString
End If
'ltEmbed.Text =< object data =C:& lsfilepath& type =application / pdfwidth =500pxheight =600px>< / object>
'msSQL =select * from tblfiles其中id ='& id& '
ltEmbed.Text = String.Format(embed,ResolveUrl(C:& lsfilepath&))
objdbconn.CloseConn()
我的路径是< object data =C:/ erp_documents / local / daily process / uploaddocuments / 2016/6 / UPLF1606230135.pdftype =application / pdf width =500pxheight =600px>< / object>
这看起来很像一个网站 - 所以这不起作用:
Process.Start( C:/ erp_documents /本地/每日流程/ uploaddocuments / 2016/6 / UPLF1606230135.pdf)
它可能正在开发中,但它不会投入生产。
C#代码始终在服务器上执行,而不是在客户端上执行,并且只能访问服务器磁盘,而不能访问客户端硬盘。因此,根据您存储PDF的位置,可能根本不可能。
因为Process.Start
代码在服务器上执行,该进程在服务器上启动 - 因此它尝试使用系统默认文件关联来打开文件并在服务器上显示它 - 客户端无法看到它。它似乎在开发中工作,因为它们是同一台机器,你无法分辨哪个机器启动了。但是在生产中它失败了。
第二个问题是,即使文件位于服务器上,您的网站也可能无法访问包含它的文件夹:IIS不会在您的用户ID下运行,所以它不会继承您的用户访问权限。你需要检查文件夹链并确保已经给出了正确的权限。
你可以在客户端显示PDF(取决于客户端和他的浏览器)通过使用Response对象,使用,有些可能将其视为下载而不是页面:
Response.ClearHeaders();
Response.ContentType = application / pdf
Response.Clear()
Response.AppendHeader( Content-Disposition, inline)
Response.TransmitFile(pathToFile)
Response.End()
I could not able to open pdf file from c drive. I tried below coding
What I have tried:
Dim lsfilename As String
Dim lsfilepath As String
hdnfilepath.Value = e.CommandArgument
Dim embed As String = "<object data=""{0}"" type=""application/pdf"" width=""500px"" height=""600px"">"
embed += "</object>"
objdbconn.OpenConn()
msSQL = "select document_gid,file_path, file_name from dap_trn_tdocuments where document_gid='" & hdnfilepath.Value & "'"
objOdbcDataReader = objdbconn.GetDataReader(msSQL)
If objOdbcDataReader.HasRows = True Then
objOdbcDataReader.Read()
lsfilename = objOdbcDataReader.Item("file_name").ToString
lsfilepath = objOdbcDataReader.Item("file_path").ToString
End If
'ltEmbed.Text = "<object data=""C:" & lsfilepath & """ type=""application/pdf"" width=""500px"" height=""600px""></object>"
'msSQL = " select * from tblfiles where id='" & id & "' "
ltEmbed.Text = String.Format(embed, ResolveUrl("C:" & lsfilepath & ""))
objdbconn.CloseConn()
My path is <object data="C:/erp_documents/local/daily process/uploaddocuments/2016/6/UPLF1606230135.pdf" type="application/pdf" width="500px" height="600px"></object>
That looks a lot like a website - so this won't work:
Process.Start("C:/erp_documents/local/daily process/uploaddocuments/2016/6/UPLF1606230135.pdf")It may appear to in development, but it won't in production.
C# code is always executed on the Server, not the Client, and only has access to Server disks, never the Client HDD. So depending on where you are storing the PDF it may not be possible at all.
Because theProcess.Start
code is executed on the Server, the process is started on the Server - so it attempts to use the system default file association to open the file and display it at the Server - the Client can't see it. It appears to work in development because they are the same machine, and you can't tell which started the process. But in production it fails.
The second problem is that even if the file is located on the server, your website may not have access to the folder containing it: IIS does not run under your user id, so it does not "inherit" your user access permissions. You need to check the folder chain and ensure that the correct privileges have been given.
You can display a PDF at the client (depending on the client and which browser he uses, some may treat it as a download rather than a page) by using the Response object:
Response.ClearHeaders(); Response.ContentType = "application/pdf" Response.Clear() Response.AppendHeader("Content-Disposition", "inline") Response.TransmitFile(pathToFile) Response.End()
这篇关于我无法从C盘打开pdf文件。我尝试了以下编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!