本文介绍了文件访问路径被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在尝试在Excel中生成报告.
我正在编写以下代码.
Hi All,
I am trying to generate a report in excel.
I am writing following code.
Dim format As System.IFormatProvider = New System.Globalization.CultureInfo(CType(Application("StrToDateFormat"), String), True)
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim strFileName, strExcelFIle As String
objDate = System.Convert.ToDateTime(tbToDate.Text, format)
strExcelFIle = "PlantUtilizationReport " + objDate.ToString("yyMMdd") + ".xls"
objDate = System.Convert.ToDateTime(tbToDate.Text, format)
strFileName = MapPath(".") & "\" & strExcelFIle
Dim TheFile As FileInfo = New FileInfo(strFileName)
If TheFile.Exists Then
File.Delete(strFileName)
End If
objDate = System.Convert.ToDateTime(tbToDate.Text, format)
' Start Excel and get Application object.
oXL = New Excel.Application
oWB = oXL.Workbooks.Open("c:\inetpub\wwwroot\LCAccounting\PantOccupancy.xls")
oSheet = oWB.ActiveSheet
oSheet.Cells(TodaysDateRow, TodaysDateCol) = tbToDate.Text
dt = obj.GetTable("SP_FGPlantUtilizationTrnSelForExcel", objDate.ToString("MM/dd/yyyy"))
Dim RowNo, colNo As Int16
For Each dr In dt.Rows
RowNo = dr("RowNo")
colNo = dr("ColNo")
oSheet.Cells(RowNo, colNo).Value = dr("UtilizationHours")
' oSheet.Cells(RowNo, DailyProductionCol).Value = dr("Qty")
Next
dt = obj.GetTable("SP_FGPlantProductionTrnSelForExcel", objDate.ToString("MM/dd/yyyy"))
For Each dr In dt.Rows
RowNo = dr("RowNo")
oSheet.Cells(RowNo, DailyProductionCol).Value = dr("Qty")
Next
但它显示以下错误:
But it shows following error :
Access is denied.<br />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.<br />
<br />
Exception Details: System.UnauthorizedAccessException: Access is denied.<br />
<br />
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.<br />
<br />
To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
堆栈跟踪:
Stack Trace:
[UnauthorizedAccessException: Access is denied.]<br />
BDRegions.Report.lbReport_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\LCAccounting\Report.aspx.vb:83<br />
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)<br />
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)<br />
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)<br />
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)<br />
System.Web.UI.Page.ProcessRequestMain() +1330<br />
请帮帮我
谢谢&问候,
Atul sharma
Please help me
Thanks & Regards,
Atul sharma
推荐答案
这篇关于文件访问路径被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!