简体   繁体   中英

Copy PDfs Files to shared network and files corrupted

My app Windows forms .NET in Win XP copy files pdfs in shared network folder in a server win 2003.

Admin user in Win2003 detects some corrupt files pdfs, in that shared folder.

HOw can I check if a file is copied right in shared folder ??

the code: I use two ways to copy/move files to shared folder

  1. NOte: my app generates PDFs files

  2. Write Bytes to disk (the shared folder)

    Public Shared Function GenerarFicheroDeBytes(ByVal datosFichero As Byte(), ByVal rutaFisicaFichero As String) As FileStream

     If Not Directory.Exists(Path.GetDirectoryName(rutaFisicaFichero)) Then Directory.CreateDirectory(Path.GetDirectoryName(rutaFisicaFichero)) End If Dim fs As New FileStream(rutaFisicaFichero, FileMode.OpenOrCreate, FileAccess.Write) fs.Write(datosFichero, 0, datosFichero.Length) fs.Flush() fs.Close() Return fs 

    End Function

2 Move File to shared network folder

Public Function MoverFicheroABuzonParaIndexar(ByVal rutaProcesarFicherosBuzon As String, ByVal nombreFichero As String) As String

Dim nombreFicheroPDF As String = String.Empty
Dim nombreFicheroPDFRenombrado As String = String.Empty
Dim nombreFicheroBuzon As String = String.Empty 

     nombreFicheroPDF = ... Path.GetFileNameWithoutExtension(...)
     nombreFicheroBuzon = ObtenerRutaFicheroBuzonParaIndexar(...)

      File.Move(nombreFicheroPDF, nombreFicheroBuzon)
Return nombreFicheroBuzon

End Function

To answer the question, unless you know the resulting format of the file - the only entity that can tell you if a file is corrupt or not is the application that attempts to use it. "Corruption" has no context outside of trying to use the file, it's like saying a .doc is corrupt because my CAD application can't read it, only Word can.

Also, File.Copy and File.Move exist as shortcut methods for moving files instead of manually streaming them yourself.

I had this problem, ended up I wasn't waiting long enough for the PDF Printer to finish printing the PDF, and I was only getting the first half or so of the file! Put a simple loop in my program to fix this:

// the file is there, make sure it is not still growing (printing). If it is, wait for it to stop
FileInfo fi = new FileInfo(OUTPUTFILEPATH);
long lastLength;
do
{
    lastLength = fi.Length;
    Thread.Sleep(1500);
    fi.Refresh();
}
while (fi.Length > lastLength);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM