blah blah blah is here! blah blah » Close

up0down
link

I got another problem::::::-----

I'm not able to reach these folders via C# code:-

C:\\Documents and Settings\\gsvsnl\\My Documents\\y Pictures\\gs.bmp
C:\\Documents and Settings\\gsvsnl\\Local Settings\\Application Data\\Microsoft\\gs.bmp


I tried something like this:-
string var1 = System.Environment.SpecialFolder.MyPictures.ToString() + "\\gs.bmp";
string var2 = System.Environment.SpecialFolderApplicationData.ToString() + "\\gs.bmp";


But I'm not able to get there..... Error popup says:
Could not find a part of the path 'MyPictures\gs.bmp'
MyPictures in the popup should have space in it na?? My Pictures What do u say????

last answered one year ago

9 answers

link

The reason why your code isn't working is because System.Environment.SpecialFolder is an enum and so the following expression:

System.Environment.SpecialFolder.MyPictures.ToString()

just returns 'MyPictures'.

To get the associated path you need to use the System.Environment.GetFolderPath() method:
string var1 = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\gs.bmp";
string var2 = Environment.GetFolderPath
(Environment.SpecialFolder.ApplicationData) + "\\gs.bmp";


However, I agree with muster that, unless you're sharing them amongst several applications, it's usually preferable to keep all your files together either in your application's directory or a sub-directory thereof.

gsvirdi
412

Thx so much for the explanation and the solution too. I do make lots of mistakes :)

up1down
link

btw the path might not be correct:
C:\\Documents and Settings\\gsvsnl\\My Documents\\y Pictures\\gs.bmp(its my pictures instead of y Pictures)

Beside this its always not preferable to store files in these directories so you might face some security problems. its better to store files in a directory in the root directory of the application by

string var1 = System.IO.Directory.GetCurrentDirectory() + "\\MyApplicationData\\gs.bmp";

gsvirdi
412

"y Pictures" was a typo mistake only. Otherwise I do take care while typing the paths :) I do agree with u (root directory), but here I just wanted that a specified file like gs.bmp should be taken as wallpaper as soon as the winform loads. I selected "My Pictures" directory bcoz this directory will be available on all computers.

up0down
link

How can I delete a file from a particular path using the code???? Is there any option to supress the "delete file confirmation" dialogue box????

up0down
link

you can delete a file by System.IO.File.Delete(filePath); to suppress the delete file confirmation dialogue box do this:

if (System.Windows.Forms.MessageBox.Show("Do you want to delete this file?", "Delete", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
System.IO.File.Delete(filePath);

up0down
link

Why is this line not correct????

.
string date = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString();
.


I'm just trying to get today's date in dd-mm-yyyy format.

up0down
link

Well, if the day and/or month is a single digit, then that's all you'll get with that expression.

I'd use:

string date = DateTime.Now.ToString("dd-MM-yyyy");

up0down
link

I was just trying to add today's date in the file name.....

string date = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString();
string filepath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\ExcelData" + date + ".xls";


Why this method was wrong???

Error is:
A field initializer cannot reference the non-static field, method, or property 'ExcelData.Form1.date'

vulpes
17279

In what way is it "wrong" ?

up0down
link

How should I calculate this function in C#????

Value = 25 Log of 10 [ 1 / y ]; ???

muster
1556

try asking a question on a different thread instead of the same thread since the question is different than the main thread question because the thread is only limited to 20 answers/questions.

up0down
link

try this:

double value;
double y;
value=25*Math.Log10(1/y)

Feedback