簡體   English   中英

System.Diagnostics.Process.Start(OutputFileName)可在本地計算機上運行,​​但不能在Web服務器上運行-vb.net

[英]System.Diagnostics.Process.Start(OutputFileName) works on local machine but not in webserver - vb.net

親愛的我在vb.net和asp.net應用程序中創建了一個函數

(1)-從前端,用戶(通過復選框)選擇頁面(list.aspx)中列出的多個文件名,然后單擊“導出”按鈕以查看單個pdf文件中的所有文檔(2)-系統獲取這些文件從數據庫中, (3)-系統將它們轉換為pdf文件格式, (4)-系統將這些pdf文件合並為單個pdf文件, (5)-系統將其理想地顯示在iframe中。

在list.aspx頁上,當有人單擊export cv時,它將執行此代碼

window.location.href = 'export-cvs.aspx?v=' + vid + '&a=' + appids.toString();

在export-cvs.aspx頁中,執行以下代碼

<object id="cvFrame" width="100%" height="500px" type="application/pdf"  data="preview-bulk-cv.ashx?v=<%= Vacancy.ID%>&a=<%= Request("a") %>"></object>

主要代碼在preview-bulk-cv.ashx頁面中,如下所示。

Public Class PDFMerge : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest


Dim vacancy = New Vacancy(context.Request("v"))
Dim sourceFiles = New List(Of String)()


For Each docPath As String In From row As DataRow In DB.GetData("query").Rows Select HttpContext.Current.Server.MapPath("~/documents") & "\" & Left(guid, 1) & "\" & Right(guid, 1) & "\" & guid & "." & System.IO.Path.GetExtension(row.Item("originalfilename")).ToLower().Substring(1)

   cnt+=1

    Dim epath As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\"  & Now.ToString("yyyy-MMM-dd-HHmmss") & "_" & cnt.Tostring & ".pdf"

    Converter.ConvertDocument(docPath, epath)
    If File.Exists(epath) Then
        sourceFiles.Add(epath)
    End If

Next

Dim OutputFileName As String = HttpContext.Current.Server.MapPath("~/Downloads") & "\" & vacancy.Title.Replace(" ", "_") & ".pdf"

PDFMerge.MergeFiles(OutputFileName, sourceFiles.ToArray)
Dim mPDFFile As FileStream = File.OpenRead(OutputFileName)
Dim mPDFFileBuffer(mPDFFile.Length - 1) As Byte
mPDFFile.Read(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFile.Close()

System.Diagnostics.Process.Start(OutputFileName)


context.Response.Clear()
context.Response.ContentType = "application/pdf"
context.Response.AddHeader("Content-Disposition", "attachment;filename=" & OutputFileName)
context.Response.AddHeader("Content-Length", mPDFFileBuffer.Length)
context.Response.OutputStream.Write(mPDFFileBuffer, 0, mPDFFileBuffer.Length)
mPDFFileBuffer = Nothing
context.Response.Flush()
context.Response.End()



End Sub
End Class    

您可以在我上面的代碼中看到。 我使用以下行打開了最終的pdf文檔。

System.Diagnostics.Process.Start(OutputFileName)

此代碼在本地服務器上有效,但在Web服務器上無效。 即當我在本地主機上運行應用程序時,pdf文件打開。 但是當應用程序存儲在Web服務器上並且該Web應用程序從任何計算機作為Web應用程序運行時,pdf文件都不會打開。 我已經在網絡服務器中檢查了正在創建的文件是否已正確合並到正確的文件夾中。

Web服務器是使用Windows構建的。 Windows 2008 R2和IIS 7.5版

我該如何運作?

我知道這個例子是C#,但是這里有一個鏈接,展示了將PDF流式傳輸到瀏覽器。 http://support.microsoft.com/kb/306654

您還可以調查Response.WriteFile()以查看它是否滿足您的需求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM