Using Visual Studio C#
When I ran the following code:
System.IO;
private void Button1_Click(object sender, System.EventArgs e)
{
//FileStream fs = File.Create(Server.MapPath("test.txt"));
FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt");
StreamWriter sw = new StreamWriter(fs);
sw.Write(TextBox1.Text);
sw.Close();
fs.Close();
}
I initially got an error message that "access was denied." The message
suggested that I give ASP.NET user access rights/permissions to the folder.
I then [manually] gave the logged in user write permission to the folder.
Then, when I ran the above code, the text file was created.
Is there another way [i.e., programatically using C#] to allow my code to
write a text file to the file system without giving access rights to a user?
Can the permissions be given to the app [the code] instead of to a user?
Any suggestions would be appreciated.
Thanks.
bebop 5 3087
Yes, you can use impersonation.
For example, you can add a line similar to this to your web.config file:
<identity impersonate="true" userName="domain\MyUserName">
password="password"/>
Here's more info on impersonation: http://msdn.microsoft.com/library/de...ersonation.asp
--
I hope this helps,
Steve C. Orr, MCSD, MVP http://SteveOrr.net
"cwbp15" <cw****@discussions.microsoft.com> wrote in message
news:5A**********************************@microsof t.com... Using Visual Studio C#
When I ran the following code:
System.IO;
private void Button1_Click(object sender, System.EventArgs e) { //FileStream fs = File.Create(Server.MapPath("test.txt")); FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt"); StreamWriter sw = new StreamWriter(fs); sw.Write(TextBox1.Text); sw.Close(); fs.Close();
}
I initially got an error message that "access was denied." The message suggested that I give ASP.NET user access rights/permissions to the folder.
I then [manually] gave the logged in user write permission to the folder.
Then, when I ran the above code, the text file was created.
Is there another way [i.e., programatically using C#] to allow my code to write a text file to the file system without giving access rights to a user? Can the permissions be given to the app [the code] instead of to a user?
Any suggestions would be appreciated.
Thanks.
bebop
That helped. Thanks Steve.
I noticed the password for my currently logged in user is in clear text when
using impersonation.
Added this line to the Application's web.config file
<identity impersonate="true" userName="username" password="password"/>
Wondering if there's a way to use impersonation and have the password
encrypted or placed elsewhere.
cwbp
"Steve C. Orr [MVP, MCSD]" wrote: Yes, you can use impersonation.
For example, you can add a line similar to this to your web.config file: <identity impersonate="true" userName="domain\MyUserName"> password="password"/>
Here's more info on impersonation: http://msdn.microsoft.com/library/de...ersonation.asp
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"cwbp15" <cw****@discussions.microsoft.com> wrote in message news:5A**********************************@microsof t.com... Using Visual Studio C#
When I ran the following code:
System.IO;
private void Button1_Click(object sender, System.EventArgs e) { //FileStream fs = File.Create(Server.MapPath("test.txt")); FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt"); StreamWriter sw = new StreamWriter(fs); sw.Write(TextBox1.Text); sw.Close(); fs.Close();
}
I initially got an error message that "access was denied." The message suggested that I give ASP.NET user access rights/permissions to the folder.
I then [manually] gave the logged in user write permission to the folder.
Then, when I ran the above code, the text file was created.
Is there another way [i.e., programatically using C#] to allow my code to write a text file to the file system without giving access rights to a user? Can the permissions be given to the app [the code] instead of to a user?
Any suggestions would be appreciated.
Thanks.
bebop
"Summary: This How To shows you how to use DPAPI from an ASP.NET Web
application or Web service to encrypt sensitive data. (7 printed pages)"
Ken http://msdn.microsoft.com/library/de...SecNetHT08.asp
"cwbp" <cw**@discussions.microsoft.com> wrote in message
news:1B**********************************@microsof t.com... That helped. Thanks Steve.
I noticed the password for my currently logged in user is in clear text when using impersonation.
Added this line to the Application's web.config file
<identity impersonate="true" userName="username" password="password"/>
Wondering if there's a way to use impersonation and have the password encrypted or placed elsewhere.
cwbp "Steve C. Orr [MVP, MCSD]" wrote:
Yes, you can use impersonation.
For example, you can add a line similar to this to your web.config file: <identity impersonate="true" userName="domain\MyUserName"> password="password"/>
Here's more info on impersonation: http://msdn.microsoft.com/library/de...ersonation.asp
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"cwbp15" <cw****@discussions.microsoft.com> wrote in message news:5A**********************************@microsof t.com... > Using Visual Studio C# > > When I ran the following code: > > System.IO; > > private void Button1_Click(object sender, System.EventArgs e) > { > //FileStream fs = File.Create(Server.MapPath("test.txt")); > FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt"); > StreamWriter sw = new StreamWriter(fs); > sw.Write(TextBox1.Text); > sw.Close(); > fs.Close(); > > } > > I initially got an error message that "access was denied." The message > suggested that I give ASP.NET user access rights/permissions to the > folder. > > I then [manually] gave the logged in user write permission to the > folder. > > Then, when I ran the above code, the text file was created. > > Is there another way [i.e., programatically using C#] to allow my code > to > write a text file to the file system without giving access rights to a > user? > Can the permissions be given to the app [the code] instead of to a > user? > > Any suggestions would be appreciated. > > Thanks. > > bebop > > >
Thanks for the information on encrypting the passwords.
I've never tried DPAPI before.
cwbp
"Ken Cox [Microsoft MVP]" wrote: "Summary: This How To shows you how to use DPAPI from an ASP.NET Web application or Web service to encrypt sensitive data. (7 printed pages)"
Ken http://msdn.microsoft.com/library/de...SecNetHT08.asp
"cwbp" <cw**@discussions.microsoft.com> wrote in message news:1B**********************************@microsof t.com... That helped. Thanks Steve.
I noticed the password for my currently logged in user is in clear text when using impersonation.
Added this line to the Application's web.config file
<identity impersonate="true" userName="username" password="password"/>
Wondering if there's a way to use impersonation and have the password encrypted or placed elsewhere.
cwbp "Steve C. Orr [MVP, MCSD]" wrote:
Yes, you can use impersonation.
For example, you can add a line similar to this to your web.config file: <identity impersonate="true" userName="domain\MyUserName"> password="password"/>
Here's more info on impersonation: http://msdn.microsoft.com/library/de...ersonation.asp
-- I hope this helps, Steve C. Orr, MCSD, MVP http://SteveOrr.net
"cwbp15" <cw****@discussions.microsoft.com> wrote in message news:5A**********************************@microsof t.com... > Using Visual Studio C# > > When I ran the following code: > > System.IO; > > private void Button1_Click(object sender, System.EventArgs e) > { > //FileStream fs = File.Create(Server.MapPath("test.txt")); > FileStream fs = File.Create("C:\\MYSAVEDFILES\\test.txt"); > StreamWriter sw = new StreamWriter(fs); > sw.Write(TextBox1.Text); > sw.Close(); > fs.Close(); > > } > > I initially got an error message that "access was denied." The message > suggested that I give ASP.NET user access rights/permissions to the > folder. > > I then [manually] gave the logged in user write permission to the > folder. > > Then, when I ran the above code, the text file was created. > > Is there another way [i.e., programatically using C#] to allow my code > to > write a text file to the file system without giving access rights to a > user? > Can the permissions be given to the app [the code] instead of to a > user? > > Any suggestions would be appreciated. > > Thanks. > > bebop > > >
This will work and u don't need to give permissions to any folder!!!
string strFilePath = "C:\\Test.txt";
FileStream fs = new FileStream(strFilePath,FileMode.Append);
StreamWriter sw = new
StreamWriter(fs,System.Text.Encoding.Default);
sw.Write("Shiva Test");
sw.Close();
Regards,
A. Shiva Kumar
--
shiva_ananthoju
------------------------------------------------------------------------
shiva_ananthoju's Profile: http://www.highdots.com/forums/m1256
View this thread: http://www.highdots.com/forums/t673445 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: melanieab |
last post by:
Hi,
I'm trying to store all of my data into one file (there're about 140 things
to keep track of). I have no problem reading a specific string from the
array file, but I wasn't sure how to...
|
by: Iceman |
last post by:
I am logging things to a file but when I kill the app and
restart it, all the other logging is gone. How can I
prevent this form happening?
|
by: simonc |
last post by:
Is there an easy way of writing a number in 32 bit integer format into four
bytes of a file? I am experimenting with FilePut but I can only make it work
by defining a four byte array and doing some...
|
by: Richard Thornley |
last post by:
Hello,
I am working on a VB.Net application and I am getting an error ONLY on the
main computer that uses the application. The main computer is on the other
coast so of course it would be the...
|
by: iwdu15 |
last post by:
how can i open a file i saved and place the info into different text boxes?
|
by: darrel |
last post by:
Our production web site went down today. We discovered that it was because
the XML file we use to create the site navigation (most all of the controls
on every page rely on this XML file) was only...
|
by: bbepristis |
last post by:
Hey all I have this code that reads from one text file writes to
another unless im on a certian line then it writes the new data however
it only seems to do about 40 lines then quits and I cant...
|
by: Craig |
last post by:
I have the need to write a byte of information to a specific location in a
text file.
eg. the file looks something like this.
FYYNN
Line 1
Line 2
<eof>
|
by: tshad |
last post by:
I have a program in 2005 that is reading a text file removing text and then
writing it back out again. It removes lines that start with PRINT.
This program has worked fine for months. Now all...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |