TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
shreyas adikumar
NA
85
10.5k
Error while reading from server to text file in localdesktop
Oct 10 2019 5:50 AM
Hi everyone i am trying to read the file into text from server i am facing the following error.Before publishing in the sever my program is working fine in visual studio after publishing i am facing that error in program
This program refrence i am attaching
string
constr6 = ConfigurationSettings.AppSettings[
"MS"
];
string
physicalPath = @
"D:\FlashdataLabel\text.txt"
;
File.WriteAllText(physicalPath, String.Empty);
FileStream stream =
new
FileStream(physicalPath, FileMode.Open, FileAccess.ReadWrite);
StreamWriter writer =
new
StreamWriter(stream);
SqlConnection con6 =
new
SqlConnection(constr6);
con6.ConnectionString = constr6;
SqlCommand com =
new
SqlCommand(
" select PMax,VOC,ISC,VPM,IPM,PSV,AssignMSN,MSN_Mat,PSN from [LabelMSN2222]where PSN='"
+ txtpsn.Text +
"' order by id desc"
, con6);
con6.Open();
SqlDataReader reader = com.ExecuteReader();
while
(reader.Read())
{
writer.Write(reader[
"PMax"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"VOC"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"ISC"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"VPM"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"IPM"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"PSV"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"AssignMSN"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"MSN_Mat"
].ToString());
writer.Write(
","
);
writer.Write(reader[
"PSN"
].ToString());
//writer.WriteLine();
}
reader.Close();
writer.Close();
stream.Close();
con6.Close();
}
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: 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
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.328
Reply
Answers (
3
)
i want convert this script in linq c#
JavaScript for a checkbox