none
C#: How to replace "\" when checking a file if exist in windows XP and windows 7? RRS feed

  • Question

  • "\" in windows XP means "C:\" folder

    "\" in windows 7 may mean "C:\Users\{UserName}\AppData\Local\VirtualStore"

    If we define a file name as "\xxx.docx" in C# application, how do we detect file if exist in both window XP and windows 7? Thx!


    JaneC


    • Edited by JJChen Wednesday, July 18, 2012 8:43 PM
    Wednesday, July 18, 2012 8:39 PM

Answers

  • I n windows XP App data is usually defined as follows

    C:\Documents and Settings\{UserName}\Application Data

    There are environmental variables set in every computer that you can reference in Xisual Studio like this

    AppData = System.Environment.GetEnvironmentVariable("AppData");

    So your file can be referenced as follows

    string FName = AppData + @"\Local\VirtualStore\xxx.docx";


    jdweng

    • Marked as answer by JJChen Wednesday, July 18, 2012 11:28 PM
    Wednesday, July 18, 2012 9:11 PM

All replies

  • I n windows XP App data is usually defined as follows

    C:\Documents and Settings\{UserName}\Application Data

    There are environmental variables set in every computer that you can reference in Xisual Studio like this

    AppData = System.Environment.GetEnvironmentVariable("AppData");

    So your file can be referenced as follows

    string FName = AppData + @"\Local\VirtualStore\xxx.docx";


    jdweng

    • Marked as answer by JJChen Wednesday, July 18, 2012 11:28 PM
    Wednesday, July 18, 2012 9:11 PM
  • Hi Jdweng,

    thanks for your information!

    I found out that we use Path.GetFullPath("\\") to get absolute path.

    In both windows XP and windows &, it will return as Path.GetFullPath("\\") = "C:\"

    However, we use third party software, it looks like they have changed the implementation to convert "\\" into different pathes. That is the reason we see the difference in windows XP and windows 7.  


    JaneC

    Wednesday, July 18, 2012 11:28 PM