Monday, March 26, 2012
Text File Processing
The problem that I am having is the starts with a 12 line header that I can through way because the first 12 line will always be the same. Where my problem is that at certain points during the file a sub set of the header file will occur. There does not seem to be any rhyme or reason as to where the entry occurs.
Does anyone have any idea how how to check for this line pattern and how I can ignore it?What I've done in cases like this is to import the file into anintermediary table, delete any rows which contain header information,and insert the remaining records into the final destination table.
Text file upload
Does anyone know of any sample code out there that allows a simple text file to be uplaoded and then stored in a SQL2005 database?
I have a system to record reports and it would be great to be able to upload and store the reports in the database and then be able to display them again via a web page linked from the record concerned.
regards
for saving a file in the database ... you have to convert it in the Binary array and save it as Binary.
On other hand ... better idea will be ... which i would do in your case ... save just the Text of the file in your Database ... make extra columns for the file meta data contents ... like ... name ... extension .. when it was created ... eidted.
then you will have more room in your database ... and ... processing in both directions will be alot faster...
Why can't you just save the filename in the database and store the actual file in another directory? That way, if you want to display it on a webpage, you can provide a link to the actual file. It would save a lot more time to do it this way then to go through the trouble of saving the document in a database table.
(In my html)
Upload Attachment:<asp:FileUpload ID="FileUpload1" runat="server" Height="20" Width="300" BorderColor="#BFBFBE"> File Types: (.doc, .pdf, .rtf, .txt, .xls).pdf, .rtf, .txt, .xls)
(In my code behind)Then call your method that will save the uploaded document to the database. This way, you know all documents will be in the uploads folder (and all files will have unique names). When you go to display this in an html page later on, you'll know the location and will just have to pull the filename from the database.
if (FileUpload1.HasFile) {string fileext = Path.GetExtension(FileUpload1.FileName).ToLower();//rtf, doc, pdf, txt, xlsif (fileext ==".doc" || fileext ==".rtf" || fileext ==".pdf" || fileext ==".txt" || fileext ==".xls") {string uniqueFileName = System.Guid.NewGuid().ToString(); HttpPostedFile hp = FileUpload1.PostedFile; hp.SaveAs(@.Request.ServerVariables["APPL_PHYSICAL_PATH"] +"uploads\\" + uniqueFileName.ToString() + fileext.ToString()); } }
Why can't you just save the filename in the database and store the actual file in another directory? That way, if you want to display it on a webpage, you can provide a link to the actual file
Acutally i would also prefer this one.
Based on my understanding, I think there may be a performance issue if you store the uploaded file in a database. So, storing the meta-data of the file into a db and the file to a file server is a better solution. Also, if the file is too large in size, i would suggest using a activeX upload control.
thanks.
omerkamal:
On other hand ... better idea will be ... which i would do in your case ... save just the Text of the file in your Database ... make extra columns for the file meta data contents ... like ... name ... extension .. when it was created ... eidted.
then you will have more room in your database ... and ... processing in both directions will be alot faster...
i totally agree with omerkamal ; saving just Text of the file in database (if only textfile is tobe uploaded) would be a better idea for fast processing.,