ti copio dall'help framework
codice:
[Visual Basic]
Imports System
Imports System.IO
Imports System.Text
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Try
Dim sw As StreamWriter = File.CreateText(path)
sw.Close()
Dim path2 As String = path + "temp"
' Ensure that the target does not exist.
File.Delete(path2)
' Copy the file.
File.Copy(path, path2)
Console.WriteLine("{0} was copied to {1}.", path, path2)
' Delete the newly created file.
File.Delete(path2)
Console.WriteLine("{0} was successfully deleted.", path2)
Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub
End Class
[C#]
using System;
using System.IO;
class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
try
{
using (StreamWriter sw = File.CreateText(path)) {}
string path2 = path + "temp";
// Ensure that the target does not exist.
File.Delete(path2);
// Copy the file.
File.Copy(path, path2);
Console.WriteLine("{0} was copied to {1}.", path, path2);
// Delete the newly created file.
File.Delete(path2);
Console.WriteLine("{0} was successfully deleted.", path2);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
void main() {
String* path = S"c:\\temp\\MyTest.txt";
try {
StreamWriter* sw = File::CreateText(path);
if (sw) __try_cast<IDisposable*>(sw)->Dispose();
String* path2 = String::Concat(path, S"temp");
// Ensure that the target does not exist.
File::Delete(path2);
// Copy the file.
File::Copy(path, path2);
Console::WriteLine(S"{0} was copied to {1}.", path, path2);
// Delete the newly created file.
File::Delete(path2);
Console::WriteLine(S"{0} was successfully deleted.", path2);
} catch (Exception* e) {
Console::WriteLine(S"The process failed: {0}", e);
}
}
se vuoi farlo andare in asp .net al posto di Console.WriteLIne usare Respone.write..