Groups > Databases > Oracle for ASP.NET > Re: Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line




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

Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line
Thu, 20 Mar 2008 19:39:46 +000
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
extensionstring[] 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 7if
(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 bytesbyte[] 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
Post Reply
Re: Uploading and Downloading Binary File(PDF) from Oracle Using C# Command Line
Fri, 21 Mar 2008 21:37:38 +000
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.
Post Reply
about | contact