[RESOLVED] Save file, need to determine XP/7
Hi. I have a problem, I need my app to determine between Win XP, Vista and Win 7 so It can deside which path to save txt file. I know this can be solved by running program as administrator and be able to save in whatever path you like but it would be good if the user didnt have to. Vista and win 7 suxx in this regard although win7 is great otherwise, use it myself.
Anyways would be nice if it was as simple as:
OS = humhum
and the if else :D
but probably not TT
Thx in advance
Re: Save file, need to determine XP/7
this info should help you.. i just googled "c# get operating system" (for you):
Code:
Console.WriteLine("Operating System Detaiils");
OperatingSystem os = Environment.OSVersion;
Console.WriteLine("OS Version: " + os.Version.ToString());
Console.WriteLine("OS Platoform: " + os.Platform.ToString());
Console.WriteLine("OS SP: " + os.ServicePack.ToString());
Console.WriteLine("OS Version String: " + os.VersionString.ToString());
Console.WriteLine();
// Get Version details
Version ver = os.Version;
Console.WriteLine("Major version: " + ver.Major);
Console.WriteLine("Major Revision: " + ver.MajorRevision);
Console.WriteLine("Minor version: " + ver.Minor);
Console.WriteLine("Minor Revision: " + ver.MinorRevision);
Console.WriteLine("Build: " + ver.Build);
Re: Save file, need to determine XP/7
Not to sound ungrateful but i work with vb .net
anyways thx :bigyello:
Re: Save file, need to determine XP/7
The 'My' namespace may have the directory you're looking for
Code:
Debug.WriteLine(My.Computer.FileSystem.SpecialDirectories.MyDocuments)
Debug.WriteLine(My.Computer.FileSystem.SpecialDirectories.Desktop)
Re: Save file, need to determine XP/7
Ty Bill but I think i will solve this the easy way.
Since the problem for me is that win7 and vista wont let the app save files werever it want I thought i simply make the app save in user folder on win XP as well. Create the path if it doesnt exist.
------------------------
If Not System.IO.Directory.Exists("C:\Users\" & System.Environment.UserName & "\Documents") Then
System.IO.Directory.CreateDirectory("C:\Users\" & System.Environment.UserName & "\Documents\")
End If
------------------------
Does this path exist on Vista? I know it does on win7 regardless of language of the OS.
Also, anyone know if theres a sign I can use instead of C: ? even though its the most common letter for the os hdd it may differ.
Re: Save file, need to determine XP/7
Their is always the non-programmatic OS shortcuts way: http://vlaurie.com/computers2/Articles/environment.htm / http://www.gdgsoft.com/pb/pbhelp/varlist.html
%USERPROFILE%\Desktop
I feel these variables will have more longevity, as they are binded to OS and have been the same for over 10 years and are likely to work 10 years from now. I am fairly certain that the other variables are simply linking to these anyhow =-0
Re: Save file, need to determine XP/7
I just tried this:
If Not System.IO.Directory.Exists("%USERPROFILE%\test") Then
System.IO.Directory.CreateDirectory("%USERPROFILE%\test")
End If
But nothing. no error and no created folder. Any ideas?
Re: Save file, need to determine XP/7
... Or you guys could just use the Framework to provide the correct path to the user's Documents folder like it's there for you to make things easier.
VS2002/2003:
Environment.GetFolderPath(Environment.SpecialFolders.WhateverFolderYouSeek)
VS2005+:
My.Computer.FileSystem.SpecialDirectories.WhateverFolderYouSeek
Just like Wild Bill has already suggested.
Re: Save file, need to determine XP/7
thx solved it:
Private Property userprofile As String
userprofile = Environ("userprofile")
Now I dont need to create a folder just use "userprofile" as the path
Re: Save file, need to determine XP/7
Quote:
Originally Posted by
SlimJim
I just tried this:
If Not System.IO.Directory.Exists("%USERPROFILE%\test") Then
System.IO.Directory.CreateDirectory("%USERPROFILE%\test")
End If
But nothing. no error and no created folder. Any ideas?
Ok, well I guess it's not the best method. Try hitting this folder from the run command: WinKey + R - Paste: %USERPROFILE%\test
%USERPROFILE% is C:\Users\USERNAME\ in Win7, not desktop or Documents and Settings.