Du skal bruge System.Diagnostics.Process i stedet for. Som du selv er inde på, så benyttes System.IO.File.Open til at åbne en fil for læsning internt i programmet.
Her er et hurtigt eksempel:
using System; using System.Collections.Generic; using System.Diagnostics; using System.Text;
namespace ProcessOutput { class Program { static void Main(string[] args) { Process proc = new Process(); proc.StartInfo = new ProcessStartInfo(); proc.StartInfo.FileName = "testfil.doc"; proc.StartInfo.CreateNoWindow = true; proc.Start(); } } }
Kig nærmere på Process.StartInfo. Der er en masse muligheder for at indstille hvordan filen/processen skal åbnes.
Synes godt om
Slettet bruger
30. december 2006 - 11:30#2
Okaj
Synes godt om
Slettet bruger
30. december 2006 - 12:01#3
Hov!
Error 1 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 17 Acer Aspire 9410 series software package Error 2 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 39 Acer Aspire 9410 series software package Error 3 The type or namespace name 'ProcessStartInfo' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 150 41 Acer Aspire 9410 series software package
Synes godt om
Slettet bruger
30. december 2006 - 12:02#4
using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Diagnostics;
Process PROCESS = new Process(); PROCESS.StartInfo = new ProcessStartInfo(); PROCESS.StartInfo.FileName = DESTINATION; PROCESS.StartInfo.CreateNoWindow = true; PROCESS.Start();
Hvor DESTINATION = filens placering (en string)
Retunerer:
Error 1 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 17 Acer Aspire 9410 series software package Error 2 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 39 Acer Aspire 9410 series software package Error 3 The type or namespace name 'ProcessStartInfo' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 150 41 Acer Aspire 9410 series software package
static void Main() { Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("Welcome to the Acer Aspire 9410 series software package installer!\nThis tool will copy a complete collection of drivers and other basic software\nfor Acer Aspire 9410 Notebooks to a selectable destination on you hard drive."); Console.SetCursorPosition(1, 8); Console.WriteLine("- Press <ENTER> to proceed."); Console.SetCursorPosition(1, 10); Console.WriteLine("- Press any other key to cancel."); Console.CursorVisible = false; if (Console.ReadKey().Key.ToString() == "Enter") { GET_DESTINATION(""); } }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); if (ERROR == "") { Console.WriteLine("You must now choose the destination directory of the package."); } else { Console.WriteLine(ERROR); } Console.SetCursorPosition(1, 6); Console.WriteLine("- Enter the path of the destination directory and press <ENTER> to proceed."); Console.SetCursorPosition(3, 7); Console.WriteLine("Destination directory:"); Console.SetCursorPosition(26, 7); Console.CursorVisible = true; DESTINATION = Console.ReadLine(); if (DESTINATION != "") { if (DESTINATION.Substring(DESTINATION.Length-1, 1) != "/" && DESTINATION.Substring(DESTINATION.Length-1, 1) != "\\" && DESTINATION.IndexOf(".") == -1) { CONFIRM_DESTINATION(DESTINATION + "\\" + DESTINATION_FILE); } else { GET_DESTINATION("Error: The destination string must not end with \'/\' or \'\\\' or contain \'.\'."); } } else { GET_DESTINATION("Error: You must choose the destination directory of the package."); }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("The Acer Aspire 9410 series software package will be copied to this directory:\n" + DISPLAY_DESTINATION); Console.SetCursorPosition(1, 7); Console.WriteLine("- Press <ENTER> to start copying to the selected directory."); Console.SetCursorPosition(1, 9); Console.WriteLine("- Press any other key to select another destination."); Console.CursorVisible = false; if (Console.ReadKey().Key.ToString() == "Enter") { COPY_PACKAGE(DESTINATION, DISPLAY_SOURCE, DISPLAY_DESTINATION); } else { GET_DESTINATION(""); } }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("Copying files now... Success!"); Console.SetCursorPosition(0, 5); Console.WriteLine("Source:"); Console.SetCursorPosition(13, 5); Console.WriteLine(DISPLAY_SOURCE); Console.SetCursorPosition(0, 6); Console.WriteLine("Destination:"); Console.SetCursorPosition(13, 6); Console.WriteLine(DISPLAY_DESTINATION); Console.SetCursorPosition(1, 9); Console.WriteLine("- Press <ENTER> to finish and open the package."); Console.SetCursorPosition(1, 11); Console.WriteLine("- Press any other key to finish without opening the package."); if (Console.ReadKey().Key.ToString() == "Enter") { Process PROCESS = new Process(); PROCESS.StartInfo = new ProcessStartInfo(); PROCESS.StartInfo.FileName = DESTINATION; PROCESS.StartInfo.CreateNoWindow = true; PROCESS.Start(); } }
} }
Synes godt om
Slettet bruger
30. december 2006 - 12:53#14
Error 1 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 17 Acer Aspire 9410 series software package Error 2 The type or namespace name 'Process' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 149 39 Acer Aspire 9410 series software package Error 3 The type or namespace name 'ProcessStartInfo' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Toke\Dokumenter\Visual Studio 2005\Projects\Acer Aspire 9410 series software package\Acer Aspire 9410 series software package\Main.cs 150 41 Acer Aspire 9410 series software package
Du skal i hvert fald som minimum have en reference til "System". Hvis den ikke er der, så højreklik på References og vælg "Add Reference" og scroll ned til "System" under fanebladet ".Net" og tryk "OK".
static void Main() { Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("Welcome to the Acer Aspire 9410 series software package installer!\nThis tool will copy a complete collection of drivers and other basic software\nfor Acer Aspire 9410 Notebooks to a selectable destination on you hard drive."); Console.SetCursorPosition(1, 8); Console.WriteLine("- Press <ENTER> to proceed."); Console.SetCursorPosition(1, 10); Console.WriteLine("- Press any other key to cancel."); Console.CursorVisible = false; if (Console.ReadKey().Key.ToString() == "Enter") { GET_DESTINATION(""); } }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); if (ERROR == "") { Console.WriteLine("You must now choose the destination directory of the package."); } else { Console.WriteLine(ERROR); } Console.SetCursorPosition(1, 6); Console.WriteLine("- Enter the path of the destination directory and press <ENTER> to proceed."); Console.SetCursorPosition(3, 7); Console.WriteLine("Destination directory:"); Console.SetCursorPosition(26, 7); Console.CursorVisible = true; DESTINATION = Console.ReadLine(); if (DESTINATION != "") { if (DESTINATION.Substring(DESTINATION.Length-1, 1) != "/" && DESTINATION.Substring(DESTINATION.Length-1, 1) != "\\" && DESTINATION.IndexOf(".") == -1) { CONFIRM_DESTINATION(DESTINATION + "\\" + DESTINATION_FILE); } else { GET_DESTINATION("Error: The destination string must not end with \'/\' or \'\\\' or contain \'.\'."); } } else { GET_DESTINATION("Error: You must choose the destination directory of the package."); }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("The Acer Aspire 9410 series software package will be copied to this directory:\n" + DISPLAY_DESTINATION); Console.SetCursorPosition(1, 7); Console.WriteLine("- Press <ENTER> to start copying to the selected directory."); Console.SetCursorPosition(1, 9); Console.WriteLine("- Press any other key to select another destination."); Console.CursorVisible = false; if (Console.ReadKey().Key.ToString() == "Enter") { COPY_PACKAGE(DESTINATION, DISPLAY_SOURCE, DISPLAY_DESTINATION); } else { GET_DESTINATION(""); } }
Console.Clear(); Console.WriteLine("ACER ASPIRE 9410 SERIES SOFTWARE PACKAGE"); Console.SetCursorPosition(0, 3); Console.WriteLine("Copying files now... Success!"); Console.SetCursorPosition(0, 5); Console.WriteLine("Source:"); Console.SetCursorPosition(13, 5); Console.WriteLine(DISPLAY_SOURCE); Console.SetCursorPosition(0, 6); Console.WriteLine("Destination:"); Console.SetCursorPosition(13, 6); Console.WriteLine(DISPLAY_DESTINATION); Console.SetCursorPosition(1, 9); Console.WriteLine("- Press <ENTER> to finish and open the package."); Console.SetCursorPosition(1, 11); Console.WriteLine("- Press any other key to finish without opening the package."); if (Console.ReadKey().Key.ToString() == "Enter") { Process PROCESS = new Process(); PROCESS.StartInfo = new ProcessStartInfo(); PROCESS.StartInfo.FileName = DESTINATION; PROCESS.StartInfo.CreateNoWindow = true; PROCESS.Start(); } }
} }
Og så en refference til System :)
Takker!
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.