Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line

Last post 03-21-2008 5:37 PM by Sojan80. 1 replies.

Sort Posts:

  • Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line

    03-20-2008, 12:39 PM
    • Member
      181 point Member
    • Sojan80
    • Member since 10-28-2004, 3:59 AM
    • WI
    • Posts 190

     I'm in the process of creating a small command line application that will write and retrieve PDF's to an Oracle BLOB field. Currently I am working on the "writing" part. I did a bit of Googling and couldn't really find an example if doing this from the command line, everything was from a web form. Am I using the right Namespaces? Is there an easier way to do this?

     

    try
        {
    
            // Get the current direcotry of the file(s)
            string currDirectory = Directory.GetCurrentDirectory();

    // Get a list of all the files in that direcotry regardless of the file extension string[] fileEntries = Directory.GetFiles(currDirectory);

    // Loop though each entry in the array and get the prsn_id, file name, and
    // 6 digit date (YYMMDD)
    foreach (string fileName in fileEntries)
    {
    // Only get those files in the directory that have the file extension "pdf"
    // and that have a file name length greater than 7
    if (fileName.EndsWith("pdf") && fileName.Length > 7)
    {
    // This gives us only the complete file name, excluding the path to file. myFileName = Path.GetFileName(fileName); // Get the file size as int. FileInfo fInfo = new FileInfo(myFileName);
    int fileSize = fInfo.Length;

    // Create a Stream Object FileStream fileStream = new FileStream(myFileName, FileMode.Open, FileAccess.Read);

    // Create Byte Array to hold file as bytes byte[] bArray = new byte[fileStream];

    // Load the array from the filestream fileStream.Read(bArray, 0, fileSize); // At this point we are ready to stick everything in the database. ... } } } catch(Exception ex)
    {
    throw ex;
    }
    Thanks  
  • Re: Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line

    03-21-2008, 5:37 PM
    Answer
    • Member
      181 point Member
    • Sojan80
    • Member since 10-28-2004, 3:59 AM
    • WI
    • Posts 190

     Well, it appears that there isn't an easier way to do this. I do however know this works as my upload is working over the command line. I still have some error trapping to do but at least it works.

Page 1 of 1 (2 items)