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)
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")
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 />
Please help me
Thanks & Regards,
Atul sharma