2016-08-26 1 views
-2

Im très nouveau pour le code et je voudrais savoir comment puis-je lier un bouton dans Visual Studio pour ouvrir un fichier sur votre bureau? System.Diagnostics.Process.Start("C:/Users/Desktop"); travail doesent Aide s'il vous plaît: DComment ouvrir un fichier sur le bureau C#

+2

Il vous manque le nom d'utilisateur ' "C:/Users//Desktop/"'. Vous pouvez obtenir le chemin vers le bureau de l'utilisateur actuel avec ceci: 'chemin de chaîne = Environment.GetFolderPath (Environment.SpecialFolder.Desktop);' –

+0

pouvez-vous donner un exaple s'il vous plaît? –

+0

Voulez-vous ouvrir un dossier? Ou voulez-vous afficher une boîte de dialogue permettant à l'utilisateur d'ouvrir un fichier sur un dossier donné? Ou voulez-vous lire le contenu du fichier? – kurakura88

Répondre

1

Voici votre exemple souhaité:

// Get the desktop folder path of the current user 
string folderpath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)‌​; 
// define the filename of the file you want to open 
string filename = "desktop.ini"; 
// Get the full path of the folder and filename combined. Path.Combine will add slash automatically 
string filepath = System.IO.Path.Combine(folderpath, filename); 
// Open the file with the defined filepath 
System.Diagnostics.Process.Start(filepath); 
+0

https://gyazo.com/57d6636d4a1086771fed36887f282286 –

+0

J'ai changé mon exemple. J'ai oublié de renommer la variable de chemin et d'utiliser system.io pour Path.Combine. –

+0

Puis-je faire ça? [lien] http://pastebin.com/5PUgJ6aY? –