/// <summary> /// 判断文件夹,是否存在,不存在则生成文件夹 /// </summary> /// <param name="keys"></param> /// <param name="postedFileName"></param> /// <param name="fileURL"></param> /// <returns></returns> public static string initFilePath(string filePath, int key) { string returnValue = filePath; try { //filePath 上传路径定义为:配置路径\ + 年月\ + 单据头PK\ + 文件名 eg: 201906\120\说明.jpg //*************除了根目录,以下其他目录都需要判断是否存在,并创建文件夹************************* Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass(); if (!fso.FolderExists(filePath)) { fso.CreateFolder(filePath); } if (!fso.FolderExists(filePath + @"\" + key)) { fso.CreateFolder(filePath + @"\" + key); } //返回文件上传路径 returnValue = returnValue + @"\" + key; //*********************************************************************************************+ } catch { } return(returnValue); }
static void Main(string[] args) { // FileSystemObjectClass-Instanz erzeugen Scripting.FileSystemObjectClass fso = new Scripting.FileSystemObjectClass(); // Laufwerk referenzieren Scripting.Drive drive = fso.GetDrive("c:"); // Informationen zum Laufwerk ausgeben Console.WriteLine("Freier Platz: {0}", drive.FreeSpace); Console.WriteLine("Größe: {0}", drive.TotalSize); Console.WriteLine("Beenden mit Return"); Console.ReadLine(); }
/// <summary> /// 上传文件并返回文件名 /// </summary> /// <param name="hifile">HtmlInputFile控件</param> /// <param name="strAbsolutePath">完整路径,包含扩展名</param> /// <returns>返回的文件名即上传后的文件名</returns> public static void SaveFileKeepName(HtmlInputFile hifile, string strAbsolutePath) { //如果上传文件的文件名不为空 if (hifile.PostedFile.FileName != string.Empty) { Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass(); //如果路径末尾为\符号,则直接上传文件 if (fso.FileExists(strAbsolutePath)) { fso.DeleteFile(strAbsolutePath, false); hifile.PostedFile.SaveAs(strAbsolutePath); } else { hifile.PostedFile.SaveAs(strAbsolutePath); } } }
/* Statische Methode zum Auslesen aller Laufwerke des Systems */ public static Drive[] GetLocalDrives() { // Instanz der Klasse FileSystemObject erzeugen Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass(); // Ergebnis-Array erzeugen Drive[] drives = new Drive[fso.Drives.Count]; // Alle Laufwerke über die Drives-Auflistung durchgehen, deren Typ, Größe // und freien Platz ermitteln und als Drive-Objekt im Array speichern int index = 0; foreach (Scripting.Drive drive in fso.Drives) { drives[index] = new Drive(); drives[index].DriveLetter = drive.DriveLetter; drives[index].Type = (DriveType)drive.DriveType; drives[index].IsReady = drive.IsReady; // Voreinstellung für die Größenangaben drives[index].AvailableSpace = -1; drives[index].FreeSpace = -1; drives[index].TotalSize = -1; if (drive.IsReady) { // Die als COM-Variant angegebenen Größenangaben in einen Long-Wert // umwandeln try { drives[index].AvailableSpace = Convert.ToInt64(drive.AvailableSpace); drives[index].FreeSpace = Convert.ToInt64(drive.FreeSpace); drives[index].TotalSize = Convert.ToInt64(drive.TotalSize); } catch {} } index++; } // Ergebnis-Array zurückgeben return(drives); }
static void Main2( string[] args ) { #region COM #region C#3 Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass( ); var stream = fso.OpenTextFile( @"C:\Archivo.txt", Scripting.IOMode.ForReading, true, Scripting.Tristate.TristateUseDefault ); #endregion #region C#4 //var fso = new Scripting.FileSystemObject(); //var stream = // fso.OpenTextFile( // Create: true, // FileName: @"C:\archivo.txt"); #endregion #endregion }
static void Main2(string[] args) { #region COM #region C#3 Scripting.FileSystemObject fso = new Scripting.FileSystemObjectClass( ); var stream = fso.OpenTextFile(@"C:\Archivo.txt", Scripting.IOMode.ForReading, true, Scripting.Tristate.TristateUseDefault); #endregion #region C#4 //var fso = new Scripting.FileSystemObject(); //var stream = // fso.OpenTextFile( // Create: true, // FileName: @"C:\archivo.txt"); #endregion #endregion }