Click here to Skip to main content
13,289,439 members (64,555 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i want to save a file with there name means volume label.
the problem is that i want to save a file in my external hard disk with hd name.

using the code it get the name of external hard disk name:

 DriveInfo[] drives = DriveInfo.GetDrives();
List<string> removables = new List<string>();
foreach (DriveInfo d in drives)
    if (d.IsReady == true)
        if (d.DriveType == DriveType.Removable)
lets suppose extnl hd name is i want to save it with path "Nayuma2013\Video\NayumaVideo".
So how to do this.
when i use this code then i get error

string adada = "Nayuma2013:\\Video\\NayumaVideo";
if (!Directory.Exists(adada))

file format path is not correct.
Posted 3-Feb-13 18:55pm
Updated 3-Feb-13 20:20pm
Joezer BH39.1K

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is not a valid directory name. If you are already have valid DriveInfo d for some drive, you can get a valid file name by using System.IO.DriveInfo.RootDirectory property:
string fileName = //... simple file name
fileName = string.Format(
Please see:[^].

If you need the file in some subdirectories, first create them under the root using System.IO.Directory.CreateDirectory:[^].


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 4 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100