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