我有DriveInfo類的這個小問題。 我知道錯誤是特定於「的isReady」屬性,但我只是不知道如何界定它..C# - 驅動器未就緒(DriveInfo)
namespace Csp.Test.ConsoleApp
{
public class Program
{
public static void Main()
{
//Create the server object - You will need create a list of the server objects.
Server server = new Server();
//Get all drives information
List<DriveInfo> driveList = DriveInfo.GetDrives().ToList<DriveInfo>();
//Insert information of one server - You will need get information of all servers
server.ServerID = 0; //Here is necessery put PK key. I recommend doing the SQL server will automatically generate the PK.
server.ServerName = string.Concat("Server ", driveList.Count);
//Inserts information in the newServers object
for (int i = 0; i < driveList.Count; i++)
{
ServerDrive serverDrives = new ServerDrive();
//Put here all the information to obeject Server
serverDrives.DriveLabel = driveList[i].Name;
serverDrives.TotalSpace = driveList[i].TotalSize;
serverDrives.DriveLetter = driveList[i].VolumeLabel;
serverDrives.FreeSpace = driveList[i].TotalFreeSpace;
// server.ListServerDrives.Add(serverDrives);
server.ServerDrives.Add(serverDrives);
}
//Add the information to an SQL Database using Linq.
DataClasses1DataContext db = new DataClasses1DataContext(@"sqlserver");
// db.Servers.InsertAllOnSubmit(server);
db.Servers.InsertOnSubmit(server);
db.SubmitChanges();
}
任何幫助將不勝感激。
你的「小問題」是什麼?你沒有描述你的代碼預期會有什麼樣的行爲,或者它實際上*具有的行爲。此外,爲什麼當代碼看起來是C#時,它被標記爲「c」? – 2012-08-07 08:52:15
由於標題指出錯誤是「驅動器未準備就緒」 ,並且在一般文章的頂部,我突出顯示「IsReady」 由於驅動器尚未準備就緒,代碼無法運行我不知道如何實施「 IsReady「進入它.. – Ghostyy 2012-08-07 08:58:28
@Ghostyy我懷疑這發生在驅動器與可移動媒體,即軟盤和光驅。您是否打算在每臺服務器上運行此代碼? – Jodrell 2012-08-07 09:05:25