2012-10-02 21 views
7

वीबी.Net का उपयोग करना सभी मैप किए गए नेटवर्क निर्देशिका/ड्राइव को ड्रॉपडाउन सूची में सूचीबद्ध करना संभव है?ड्रॉपडाउन सूची में सभी मैप किए गए नेटवर्क ड्राइव प्राप्त करें

मैं goggled है, लेकिन नहीं कर सकते कुछ भी उपयोगी पाते हैं ..

उत्तर

6

एक DropDownList में जोड़ने के लिए:

Private Sub TestCase1() 
     Dim drive As System.IO.DriveInfo 

    For Each drive In System.IO.DriveInfo.GetDrives() 
     If drive.DriveType = IO.DriveType.Network Then 
      DropDownList1.Items.Add(drive.Name) 
     End If 
    Next 
End Sub 

यह कैसे मैं सी # में कर देगी:

private void TestCase1() 
    { 

     //Recurse through the drives on this system and add them to the new DropDownList DropDownList1 if they are a network drive. 
     foreach(System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives()) 
     { 
      //This check ensures that drive is a network drive. 
      if (drive.DriveType == System.IO.DriveType.Network) 
      { 
       //If the drive is a network drive we add it here to a combobox. 
       DropDownList1.Items.Add(drive); 
      } 
     } 
    } 
1

माइक एक अच्छा जवाब है, जिसके लिए मैं इसे खोलने पर हर बार बढ़ने से रोकने के लिए कुछ जोड़ूंगा। कहने के लिए अच्छा .... वीबी में कॉम्बो बॉक्स।

Dim drive As System.IO.DriveInfo 

If DropDownList1.Count < 1 

    For Each drive In System.IO.DriveInfo.GetDrives() 

     If drive.DriveType = IO.DriveType.Network Then 

      DropDownList1.Items.Add(drive.Name) 

     End If 
    Next 
End If