We help IT Professionals succeed at work.

Process.start do not find existing file

Riccardo Mondaini
on
104 Views
Last Modified: 2017-12-02
Hi, I use the function Process.Start with filename to open file using file type; The file is stored in the localized special folder C:\Utenti\..... I'm Italian and the folder C:\Users is stored as C:\Utenti
The function returns "File not found" also the file exists. If I change "Utenti" with "Users" the file is found.
But is not possible to translate this folder name because my program can be used by German, French.... users and any nationality has a different folder name.
How can I solve this problem? Why the Process.Start do not manage the localization? If I click on a file  from Explorer, the file is find.

Thanks
Riccardo Mondaini
Comment
Watch Question

Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
how's your codes look like which trigger the Process.Start command?

Author

Commented:
My code is:
 info = New ProcessStartInfo(code) With {.UseShellExecute = True}
 info.ErrorDialog = False
 Dim res = Process.Start(info)


and the code variable contains "C:\Utenti\riccardomondaini\documenti\document.pdf"
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
ok, so how you construct the object: code ?
CERTIFIED EXPERT

Commented:
The folder name of C:\Users is just a wicked tweak by Microsoft.

They have introduced a link to it (Utenti, Benutzer, ...) to give the illusion of a language dependent name of that directory, but there's allways "Users" inside. So you could use "Users" everywhere.

Besides of that you coulld use the environment variable USERPROFILE to access the users's home directory. There's much mor info in the environment - have a look at it.

Author

Commented:
Object code is defines as:

Dim code as string = "C:\Utenti\riccardomondaini\documenti\document.pdf"

Author

Commented:
Hi frankhelk,
the program does not know the name of the file that is passed by the caller. The file can be on any path.
Only when the file is located on a specialfolder, the file is not found. Furthermore, not only the first node is located (UserProfile), but also the next subfolder (Images, Documents ...)
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
you can try look for: Environment.GetFolderPath method.

for example:

Dim myPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

Open in new window


and then for your codes:

Dim myPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Dim code as string = myPath  & "\documenti\document.pdf" 

Open in new window

Author

Commented:
Hi Ryan, your solution is not correct for the reason explained to frankhelk.

This problem is very difficult to solve and cannot solved using System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) because the path name can contain any folder and not only UserProfile path. Moreover the "Documenti" subfolder is stored as "Documents". More pieces of specialfolder are localized.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
your solution is not correct for the reason explained to frankhelk
well, i'm not writting above' codes for frankhelk but based on your question.

This problem is very difficult to solve and cannot solved using System.Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) because the path name can contain any folder and not only UserProfile path.
if there's a logic, thing would be likely can be resolved. so you need to tell us the exact logic of it.

Author

Commented:
The application shows a list of documents stored in the File System using a grid.
The user double click a cell that contains a document you want to view. This document can be stored in any drive and folder.
The Double click event receive the file name to view and use the Process.Start(filename) to open the document using the file type associated program.
But if the document is stored in the SpecialFolder, the Process.Start returns "File not found" even if the file exists.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
The application shows a list of documents stored in the File System using a grid.
what kind of grid are you using here? is it loaded from a database? do you keep the valid path in the source?

Author

Commented:
The grid is loaded from the file system and lists all files that meet certain requirements.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
I'm still not very clear how you loaded the details into your "grid" (and I'm not too sure what grid control are you mentioning here).

if that source is valid, you can then generate your path accordingly based on your source. Your click event should based on this path as well.

Author

Commented:
Sorry, but the problem is not the grid; the problem is that if you use the process.start function passing as parameter a filename stored in the special folders path, the system returns a "File not found" error even if the file exists.
If you are english, you have not this problem because not localization is performed by Windows. But if you are Italian, French, German.... the SpecialFolders name are localized and this localization produces this problem.
CERTIFIED EXPERT

Commented:
Hmmm ... as far as I understand that, process.start seems to miss the resolution of the special folders.

If I had to circumvent that, I'd just enumerate thru the special forlders (given by the members of System.Environment.SpecialFolders). For the results I'd get the localized display name with this code I've just shameless ripped from some other web page:

using System.Runtime.InteropServices;

public const uint SHGFI_DISPLAYNAME = 0x000000200;     // get display name
public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;

[DllImport("shell32")]
public static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, 
    out SHFILEINFO psfi, uint cbFileInfo, uint flags);

[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
    public IntPtr hIcon;
    public IntPtr iIcon;
    public uint dwAttributes;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
    public string szDisplayName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
    public string szTypeName;
};


public  static string GetDisplayName(string path)
{
    SHFILEINFO shfi = new SHFILEINFO();
    if (0 != SHGetFileInfo(path,FILE_ATTRIBUTE_NORMAL,out shfi,
        (uint)Marshal.SizeOf(typeof(SHFILEINFO)),SHGFI_DISPLAYNAME))
    {
        return shfi.szDisplayName;
    }
    return null;
}

Open in new window


I'd create objects containing two strings, the "real" path and the "localized" path, and stuff 'em into a collection.

I'd attach a method

public String normalize(Collection, String)

to these objects which enumerates thru the collection and replaces every occurence of a localized path with its "real" path.

The result (the "normalized" path) should be sufficient for process.start.

Author

Commented:
I need to resolve the problem for any localized special folders (spanish, italian, german, chinese...)
Special folders are many. I prefer a solution that works as the Windows Explorer.



   Private Const FOLDERID_NetworkFolder = "{D20BEEC4-5CA8-4905-AE3B-BF251EA09B53}"
    Private Const FOLDERID_ComputerFolder = "{0AC0837C-BBF8-452A-850D-79D08E667CA7}"
    Private Const FOLDERID_InternetFolder = "{4D9F7874-4E0C-4904-967B-40B0D20C3E4B}"
    Private Const FOLDERID_ControlPanelFolder = "{82A74AEB-AEB4-465C-A014-D097EE346D63}"
    Private Const FOLDERID_PrintersFolder = "{76FC4E2D-D6AD-4519-A663-37BD56068185}"
    Private Const FOLDERID_SyncManagerFolder = "{43668BF8-C14E-49B2-97C9-747784D784B7}"
    Private Const FOLDERID_SyncSetupFolder = "{0F214138-B1D3-4a90-BBA9-27CBC0C5389A}"
    Private Const FOLDERID_ConflictFolder = "{4bfefb45-347d-4006-a5be-ac0cb0567192}"
    Private Const FOLDERID_SyncResultsFolder = "{289a9a43-be44-4057-a41b-587a76d7e7f9}"
    Private Const FOLDERID_RecycleBinFolder = "{B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC}"
    Private Const FOLDERID_ConnectionsFolder = "{6F0CD92B-2E97-45D1-88FF-B0D186B8DEDD}"
    Private Const FOLDERID_Fonts = "{FD228CB7-AE11-4AE3-864C-16F3910AB8FE}"
    Private Const FOLDERID_Desktop = "{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}"
    Private Const FOLDERID_Startup = "{B97D20BB-F46A-4C97-BA10-5E3608430854}"
    Private Const FOLDERID_Programs = "{A77F5D77-2E2B-44C3-A6A2-ABA601054A51}"
    Private Const FOLDERID_StartMenu = "{625B53C3-AB48-4EC1-BA1F-A1EF4146FC19}"
    Private Const FOLDERID_Recent = "{AE50C081-EBD2-438A-8655-8A092E34987A}"
    Private Const FOLDERID_SendTo = "{8983036C-27C0-404B-8F08-102D10DCFD74}"
    Private Const FOLDERID_Documents = "{FDD39AD0-238F-46AF-ADB4-6C85480369C7}"
    Private Const FOLDERID_Favorites = "{1777F761-68AD-4D8A-87BD-30B759FA33DD}"
    Private Const FOLDERID_NetHood = "{C5ABBF53-E17F-4121-8900-86626FC2C973}"
    Private Const FOLDERID_PrintHood = "{9274BD8D-CFD1-41C3-B35E-B13F55A758F4}"
    Private Const FOLDERID_Templates = "{A63293E8-664E-48DB-A079-DF759E0509F7}"
    Private Const FOLDERID_CommonStartup = "{82A5EA35-D9CD-47C5-9629-E15D2F714E6E}"
    Private Const FOLDERID_CommonPrograms = "{0139D44E-6AFE-49F2-8690-3DAFCAE6FFB8}"
    Private Const FOLDERID_CommonStartMenu = "{A4115719-D62E-491D-AA7C-E74B8BE3B067}"
    Private Const FOLDERID_PublicDesktop = "{C4AA340D-F20F-4863-AFEF-F87EF2E6BA25}"
    Private Const FOLDERID_ProgramData = "{62AB5D82-FDC1-4DC3-A9DD-070D1D495D97}"
    Private Const FOLDERID_CommonTemplates = "{B94237E7-57AC-4347-9151-B08C6C32D1F7}"
    Private Const FOLDERID_PublicDocuments = "{ED4824AF-DCE4-45A8-81E2-FC7965083634}"
    Private Const FOLDERID_RoamingAppData = "{3EB685DB-65F9-4CF6-A03A-E3EF65729F3D}"
    Private Const FOLDERID_LocalAppData = "{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}"
    Private Const FOLDERID_LocalAppDataLow = "{A520A1A4-1780-4FF6-BD18-167343C5AF16}"
    Private Const FOLDERID_InternetCache = "{352481E8-33BE-4251-BA85-6007CAEDCF9D}"
    Private Const FOLDERID_Cookies = "{2B0F765D-C0E9-4171-908E-08A611B84FF6}"
    Private Const FOLDERID_History = "{D9DC8A3B-B784-432E-A781-5A1130A75963}"
    Private Const FOLDERID_System = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}"
    Private Const FOLDERID_SystemX86 = "{D65231B0-B2F1-4857-A4CE-A8E7C6EA7D27}"
    Private Const FOLDERID_Windows = "{F38BF404-1D43-42F2-9305-67DE0B28FC23}"
    Private Const FOLDERID_Profile = "{5E6C858F-0E22-4760-9AFE-EA3317B67173}"
    Private Const FOLDERID_Pictures = "{33E28130-4E1E-4676-835A-98395C3BC3BB}"
    Private Const FOLDERID_ProgramFilesX86 = "{7C5A40EF-A0FB-4BFC-874A-C0F2E0B9FA8E}"
    Private Const FOLDERID_ProgramFilesCommonX86 = "{DE974D24-D9C6-4D3E-BF91-F4455120B917}"
    Private Const FOLDERID_ProgramFilesX64 = "{6D809377-6AF0-444b-8957-A3773F02200E}"
    Private Const FOLDERID_ProgramFilesCommonX64 = "{6365D5A7-0F0D-45e5-87F6-0DA56B6A4F7D}"
    Private Const FOLDERID_ProgramFiles = "{905e63b6-c1bf-494e-b29c-65b732d3d21a}"
    Private Const FOLDERID_ProgramFilesCommon = "{F7F1ED05-9F6D-47A2-AAAE-29D317C6F066}"
    Private Const FOLDERID_AdminTools = "{724EF170-A42D-4FEF-9F26-B60E846FBA4F}"
    Private Const FOLDERID_CommonAdminTools = "{D0384E7D-BAC3-4797-8F14-CBA229B392B5}"
    Private Const FOLDERID_Music = "{4BD8D571-6D19-48D3-BE97-422220080E43}"
    Private Const FOLDERID_Videos = "{18989B1D-99B5-455B-841C-AB7C74E4DDFC}"
    Private Const FOLDERID_PublicPictures = "{B6EBFB86-6907-413C-9AF7-4FC2ABF07CC5}"
    Private Const FOLDERID_PublicMusic = "{3214FAB5-9757-4298-BB61-92A9DEAA44FF}"
    Private Const FOLDERID_PublicVideos = "{2400183A-6185-49FB-A2D8-4A392A602BA3}"
    Private Const FOLDERID_ResourceDir = "{8AD10C31-2ADB-4296-A8F7-E4701232C972}"
    Private Const FOLDERID_LocalizedResourcesDir = "{2A00375E-224C-49DE-B8D1-440DF7EF3DDC}"
    Private Const FOLDERID_CommonOEMLinks = "{C1BAE2D0-10DF-4334-BEDD-7AA20B227A9D}"
    Private Const FOLDERID_CDBurning = "{9E52AB10-F80D-49DF-ACB8-4330F5687855}"
    Private Const FOLDERID_UserProfiles = "{0762D272-C50A-4BB0-A382-697DCD729B80}"
    Private Const FOLDERID_Playlists = "{DE92C1C7-837F-4F69-A3BB-86E631204A23}"
    Private Const FOLDERID_SamplePlaylists = "{15CA69B3-30EE-49C1-ACE1-6B5EC372AFB5}"
    Private Const FOLDERID_SampleMusic = "{B250C668-F57D-4EE1-A63C-290EE7D1AA1F}"
    Private Const FOLDERID_SamplePictures = "{C4900540-2379-4C75-844B-64E6FAF8716B}"
    Private Const FOLDERID_SampleVideos = "{859EAD94-2E85-48AD-A71A-0969CB56A6CD}"
    Private Const FOLDERID_PhotoAlbums = "{69D2CF90-FC33-4FB7-9A0C-EBB0F0FCB43C}"
    Private Const FOLDERID_Public = "{DFDF76A2-C82A-4D63-906A-5644AC457385}"
    Private Const FOLDERID_ChangeRemovePrograms = "{df7266ac-9274-4867-8d55-3bd661de872d}"
    Private Const FOLDERID_AppUpdates = "{a305ce99-f527-492b-8b1a-7e76fa98d6e4}"
    Private Const FOLDERID_AddNewPrograms = "{de61d971-5ebc-4f02-a3a9-6c82895e5c04}"
    Private Const FOLDERID_Downloads = "{374DE290-123F-4565-9164-39C4925E467B}"
    Private Const FOLDERID_PublicDownloads = "{3D644C9B-1FB8-4f30-9B45-F670235F79C0}"
    Private Const FOLDERID_SavedSearches = "{7d1d3a04-debb-4115-95cf-2f29da2920da}"
    Private Const FOLDERID_QuickLaunch = "{52a4f021-7b75-48a9-9f6b-4b87a210bc8f}"
    Private Const FOLDERID_Contacts = "{56784854-C6CB-462b-8169-88E350ACB882}"
    Private Const FOLDERID_SidebarParts = "{A75D362E-50FC-4fb7-AC2C-A8BEAA314493}"
    Private Const FOLDERID_SidebarDefaultParts = "{7B396E54-9EC5-4300-BE0A-2482EBAE1A26}"
    Private Const FOLDERID_TreeProperties = "{5b3749ad-b49f-49c1-83eb-15370fbd4882}"
    Private Const FOLDERID_PublicGameTasks = "{DEBF2536-E1A8-4c59-B6A2-414586476AEA}"
    Private Const FOLDERID_GameTasks = "{054FAE61-4DD8-4787-80B6-090220C4B700}"
    Private Const FOLDERID_SavedGames = "{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}"
    Private Const FOLDERID_Games = "{CAC52C1A-B53D-4edc-92D7-6B2E8AC19434}"
    Private Const FOLDERID_RecordedTV = "{bd85e001-112e-431e-983b-7b15ac09fff1}"
    Private Const FOLDERID_SEARCH_MAPI = "{98ec0e18-2098-4d44-8644-66979315a281}"
    Private Const FOLDERID_SEARCH_CSC = "{ee32e446-31ca-4aba-814f-a5ebd2fd6d5e}"
    Private Const FOLDERID_Links = "{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}"
    Private Const FOLDERID_UsersFiles = "{f3ce0f7c-4901-4acc-8648-d5d44b04ef8f}"
    Private Const FOLDERID_SearchHome = "{190337d1-b8ca-4121-a639-6d472d16972a}"
    Private Const FOLDERID_OriginalImages = "{2C36C0AA-5812-4b87-BFD0-4CD0DFB19B39}"
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
well, info is useful when trying to provide a suggestion. at this point of time, i'm not sure how you load the details into your "grid", whether are we able to view the file path in your grid, how's your source looks like, etc? so with limited details it would be difficult to provide further suggestions.

Author

Commented:
Hi Ryan, to test this problem, you have to
change your localization from english to italian or french or german....
create a simple VB.NET program with the funcion Process.Start("C:\Utenti")
and you can see the error also if the folder is existing
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer / Applications Consultant
CERTIFIED EXPERT

Commented:
hi,

Process.Start("C:\Utenti")
"C:\Utenti" is a string value, I don't think localization will affect the value of it.

From your original output:
C:\Utenti\riccardomondaini\documenti\document.pdf
I guess you want to get user's document folder? if yes, you can try this:
Dim myPath As String = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
        Dim code As String = System.IO.Path.Combine(myPath, "document.pdf")

Open in new window

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.