none
path in wpf

    Question

  • hi all

    i have really problem with my app

    i need to my exe application for the first time started in any account automaticlly made the folders for put the files in it

    like >> img folder by img name for my pictures

                pdf folder by pdffile name for my pdf files

                or ......

    thanks quys pls help me

    Thursday, May 16, 2019 10:33 AM

All replies

  • hi all

    i have really problem with my app

    i need to my exe application for the first time started in any account automaticlly made the folders for put the files in it

    like >> img folder by img name for my pictures

                pdf folder by pdffile name for my pdf files

                or ......

    thanks quys pls help me

    Hi aminam,

    According to your description, you want to create folder by file name when you save any file, am I right? If yes, I do one sample about creating  folder by file name on root dictionary for saving file.

    string rootpath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                
                string filename = System.IO.Path.GetFileNameWithoutExtension(filepath);
                var imagePath = rootpath + @"\MyAppName\"+filename;
    
                if (!Directory.Exists(imagePath))
                {
                    DirectoryInfo di = Directory.CreateDirectory(imagePath);
                }

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 17, 2019 5:59 AM
    Moderator
  • Sorry to jump in here.

    Please bear in mind a live user will not be able to write to the same folder a program is usually installed in. Unless they are using windows xp or the app is forced to run with admin privileges. ( The latter is almost certainly a bad idea ).

    https://social.technet.microsoft.com/wiki/contents/articles/30915.c-local-files.aspx

    It's usual to use appdata for this sort of thing.

    There are conventions usually applied.

    You have a folder per supplier, within that a folder per app. You can optionally also have a productversion.

    Base Path\CompanyName\ProductName\ProductVersion

    Base Path can be public for a multi user app or the user's but would usually be %localappdata% Which is C:\Users\Andrew\AppData\Local  for me, on my machine.

    Appdata is a hidden folder BTW. In file manager you need to navigate to your user folder and tick the "hidden items" checkbox under View in order to see it.

    I think maybe the question means a pdf folder and an img folder literally so 

    Base Path\CompanyName\ProductName\Img

    There are framework "special folders" defined such as:

    var appDataLocal = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

    When building paths there's system.IO.Path.Combine https://docs.microsoft.com/en-us/dotnet/api/system.io.path.combine?view=netframework-4.8

    In an app which re-uses special paths it's usual to abstract away obtaining these and provide them via a static. Hence you have one point to change should you decide you want your files on the F drive or something.

    EG for our game GeneralStaff:

            static FilesIO()
            {
                string generalStaffFolder = GeneralStaffFolder =
                     Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
                    , "GeneralStaff");
                string blackPowderFolder = BlackPowderFolder = Path.Combine(generalStaffFolder, "BlackPowder");
                string armiesFolder = ArmiesFolder = Path.Combine(blackPowderFolder, "Armies");


    Hope that helps.

    Technet articles: WPF: Layout Lab; All my Technet Articles

    Friday, May 17, 2019 9:13 AM
    Moderator