views:

52

answers:

2

Hi all,

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 fileis copied right in shared folder ?? thanks !!

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

Greetings

thanks in advanced, please

A: 

Hi,

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.

Adam
If is PDF file ??, 2 issues: 1. how detect File Header is correct?. 2. how know if PDF is corrupt ??. thanks
alhambraeidos
Not sure, you would need to find out what the correct format is for the PDF file, and any headers, then test the current format against this correct format for validity.
Adam
A: 

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);
Adam Nofsinger