このアプリケーションは、契約ファイルをC:\Contractsに保存します。契約はaspxWebページに記入され、送信時に契約は.htmファイルとしてそのディレクトリに保存され、契約へのファイルパスはOnlineCustomerDocumentsオブジェクトに保存され、データベースに送信されます。後で、Webアプリを介してWebブラウザーでこれらの契約を開くことができるようにしたいと考えています。顧客はグリッドビューに表示され、各行に契約リンクが表示されます。
これは私が契約を開くために今持っているコードです:
protected void grdWebs_RowCommand(object sender, GridViewCommandEventArgs e)
{
int intId = 0;
Web objWeb = new Web();
try
{
string strContractFilePath;
GridViewRow row1;
List<OnlineCustomerDocuments> lstOnlineCustomerDocuments;
OnlineCustomerDocuments contract;
string strContractpath;
switch (e.CommandName)
{
case "View_Details":
//GridViewRow row = (GridViewRow) (((Button)e.CommandSource).NamingContainer);
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
intId = Convert.ToInt32(grdWebs.DataKeys[row.RowIndex].Value.ToString());
Response.Redirect("DetailsForm.aspx?Id=" + intId.ToString(), false);
break;
case "Print_Contract":
strContractFilePath = ConfigurationManager.AppSettings["CustomerContractsDirectory"].ToString();
row1 = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
intId = Convert.ToInt32(grdWebs.DataKeys[row1.RowIndex].Value.ToString());
objWeb = QDServiceHelper._QDClient.GetDetails(intId);
lstOnlineCustomerDocuments = QDServiceHelper._QDClient.GetOnlineCustomerDocumentsByID(intId);
contract = lstOnlineCustomerDocuments.ElementAt(0);
strContractpath = contract.DocumentFileName;
System.Diagnostics.Process.Start(strContractpath);
break;
default:
break;
}
}
catch (Exception ex)
{
log.Error(ex.ToString());
}
}
契約を開始するためのボタン:
<asp:LinkButton ID="btnPrintContract" runat="server" CommandName="Print_Contract" Text="View Signed Contract" width="100px" CssClass ="GeneralHyperlink"></asp:LinkButton>
基本的に、選択された行が取得され、その顧客IDの契約が取得されます。ローカルマシンでアプリケーションをテストすると、コントラクトが作成され、データベースが適切に更新され、コントラクトを開くことができます。ただし、アプリをWebサーバーに公開すると、契約を開くことができません。コードはProcess.start()まで実行されますが、その後は何も起こりません。ファイルパスを確認しましたが、リンクボタンの__doPostBackが正しいことを確認しました。私が考えることができる唯一のことは、いくつかの許可の問題があるということです。その場合は、asp.netのなりすましなどを使用してこれらのアクセス許可を付与する方法を試してみることをお勧めしますか、それともより良い方法がありますか?
更新*
だから私はhtmlドキュメントを読み、ネイサンが提案したように応答書き込みを使用しようとしましたが、新しいウィンドウで開くためにコントラクトが本当に必要であり、いくつかの異なるwindow.openメソッドを試してみましたが、それを機能させることができませんでした。提案されたように仮想ディレクトリを設定することになり、すべてがうまく機能するようになりました。以下のコードを更新しました。ネイサンの助けをありがとう。
string strContractFilePath;
GridViewRow row1;
List<OnlineCustomerDocuments> lstOnlineCustomerDocuments;
OnlineCustomerDocuments contract;
string strfileName;
string file;
string pathlead;
string vDir = "/Webfiles/";
switch (e.CommandName)
{
case "View_Details":
//GridViewRow row = (GridViewRow) (((Button)e.CommandSource).NamingContainer);
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
intId = Convert.ToInt32(grdWebs.DataKeys[row.RowIndex].Value.ToString());
Response.Redirect("DetailsForm.aspx?Id=" + intId.ToString(), false);
break;
case "Print_Contract":
strContractFilePath = ConfigurationManager.AppSettings["CustomerContractsDirectory"].ToString();
row1 = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
intId = Convert.ToInt32(grdWebs.DataKeys[row1.RowIndex].Value.ToString());
lstOnlineCustomerDocuments = QDServiceHelper._QDClient.GetOnlineCustomerDocumentsByID(intId);
contract = lstOnlineCustomerDocuments.ElementAt(0);
strfileName = contract.DocumentFileName;
//path to the virtual directory on server
pathlead = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority);
if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("CA"))
{
vDir = "/CA/WebFiles/CA1003/Contracts/";
file = pathlead + vDir + strfileName;
//Response.Redirect("~/WebFiles/contract.htm");
Response.Write("<script>");
Response.Write("window.open('" + file + "','_blank')");
Response.Write("</script>");
}
//For testing on local machines
else
{
System.Diagnostics.Process.Start(strContractFilePath + strfileName);
}
break;