Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2005
    Messaggi
    37

    Cancellazione files dal server

    Ciao!
    Ora che posso fare l'upload sul server di files e dato che memorizzo questo percorso nel database: upload\nomefile.ext vorrei poter apportare delle modifiche del tipo: cancellare il record dal db compreso il file dal server...ma come faccio a cancellare un file????


    grazie ancora

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    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..

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.