I have a file upload control on my asp.net website (C #) that is used to upload csv files with data to be inserted into the database, my problem is that I could not get the actual path of the downloaded file
It always gave me: C:\inetput\projectfolder\csvname.csv where it should have looked like: C:\Documents and settings\Pcname\Desktop\csvname.csv
but after going through various messages about downloading files, I found out that the file must first be saved on the server,
using Fileupload1.Saveas(savepath);
which is required to save the file in the previously specified location, where it is not actually required. (as this will increase the overhead of re-deleting the file).
what i am doing is as follows:
bool result = true; strm = FileUpload1.PostedFile.InputStream; reader2 = new System.IO.StreamReader(strm); // **** new **** FileInfo fileinfo = new FileInfo(FileUpload1.PostedFile.FileName); string savePath = "c:\\"; // example "c:\\temp\\uploads\\"; could be any path string fileName = fileinfo.Name; string strFilePath = savePath.ToString(); savePath += fileName; FileUpload1.SaveAs(savePath); string strSql = "SELECT * FROM [" + fileinfo.Name + "]"; string strCSVConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePath + ";" + "Extended Properties='text;HDR=NO;'"; // load the data from CSV to DataTable OleDbDataAdapter oleda = new OleDbDataAdapter(strSql, strCSVConnString); DataTable dtbCSV = new DataTable(); oleda.Fill(dtbCSV); if (dtbCSV.Columns.Count != 2) { result = false; }
because I want to count the number of columns in a file, I use an oledb reader. which needs a file request.
Can I request a stream? I do not want to save the file, but just read it without saving.
source share