Preetham Thangamma

Preetham Thangamma

  • NA
  • 118
  • 3.7k

how to write the data to the textfile from the server?

Oct 10 2019 7:27 AM
Good Morning,
 
I am facing a trouble in writing the data to the textfile from the server...and i am finding the following error....please do help me solve it...
 
Thank you
 
Server Error in '/' Application.
Access to the path 'D:\FlashdataLabel\text.txt' is denied.
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.
Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\FlashdataLabel\text.txt' is denied.
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 and IIS 7, and the configured application pool identity on IIS 7.5) 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.
To grant ASP.NET access to a file, right-click the file in File 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.
Source Error:
Line 151: string constr6 = ConfigurationSettings.AppSettings["MSdbconnection"];
Line 152: string physicalPath = @"D:\FlashdataLabel\text.txt";
Line 153: File.WriteAllText(physicalPath, String.Empty);
Line 154: FileStream stream = new FileStream(physicalPath, FileMode.Open, FileAccess.ReadWrite);
Line 155: StreamWriter writer = new StreamWriter(stream);
Source File: c:\inetpub\wwwroot\PRISM\UI\Master\HCM\MSN1.aspx.cs Line: 153
Stack Trace:
[UnauthorizedAccessException: Access to the path 'D:\FlashdataLabel\text.txt' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +417
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1217
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +144
System.IO.StreamWriter.CreateFile(String path, Boolean append, Boolean checkHost) +123
System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) +103
System.IO.File.InternalWriteAllText(String path, String contents, Encoding encoding, Boolean checkHost) +81
UI_City_CityMaster.labelMsn() in c:\inetpub\wwwroot\PRISM\UI\Master\HCM\MSN1.aspx.cs:153
UI_City_CityMaster.LoadMsn() in c:\inetpub\wwwroot\PRISM\UI\Master\HCM\MSN1.aspx.cs:138
UI_City_CityMaster.txtpsn_TextChanged(Object sender, EventArgs e) in c:\inetpub\wwwroot\PRISM\UI\Master\HCM\MSN1.aspx.cs:212
System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +137
System.Web.UI.Page.RaiseChangedEvents() +156
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4593

Answers (4)