folder - Writing to a subfolder in c# -


I have trouble writing a text file in a folder, which I tried to create. He said that I do not have access to 'C: \'

Can anyone tell me how to fix this and how? Thanks! string file_name = Environment.CurrentDirectory; File_name + = @ "\."; File_name = (string) kababox 1. Selected value; File_name + = @ "\."; File_name + = (wire) combobox2.SelectedValue; TextWriter name = new streamer (file_name); Edit

Edit: New code after modifications ...

  var location = path. Cobine (environment. Current directory, (string) combobox1. Selected item); Directory.CreateDirectory (location); Var path = path Cobain (location, combobox 2. selected ingots); TextWriter name = new streamer (path, true);   

My goal is \\. Txt

Write a text file can someone tell me how? Thanks!

The solution is that what the others have said.

As already mentioned, this line:

  file_name = (string) combobox1. Selected value;   

An assignment ( = ) is incorrectly done instead of an assembly ( + = ). This means that if comboxbo1 The selected value is null , your way . , which is the root directory of the drive.

You must remember that it is legal for SelectedValue for null , because there can be an empty selection in a combo box, in that case To handle, perhaps disabling your saved functionality until the combo box has valid selection.

This is actually not a problem with permissions; It is not possible that you really want to write in the root directory or the root directory, which is why you are not allowed in the first place.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -