abekiiPca3
New Member
I was asked to create a program that a user can browse from his local or any network drive some txt file, parse it per line with delimiter and store it in DB. The problem is my code can not get the exact URL, instead it returns the URL where the solution of the app is installed thus, returning error saying file not found. I have been looking around and I am aware asp .net can not get the exact file path, the best there is file upload. Is there a way that I do not have to save it in the solution folder/server before I can read it?my code is this:\[code\]protected void btnUploadSave_Click(object sender, EventArgs e) { string path = string.Format( CultureInfo.InvariantCulture, Strings.NewObjectPath, _root, fuUpload.FileName); //string x = fuUpload.PostedFile.FileName; OpenFile(path); }\[/code\]it returns the path but not the actual location of the project.ex. the actual location is c:\my docs\download\someFile.txt, it returns c:\my docs\vs 2010\Project\myAppSoltn\someFile.txtIf it is not possible to get the exact file loc because of security issues, is there a way I can open the file by just knowing the filename? lcode below does not work but I would liek to get something like that?\[code\]private void OpenFile(String path) { path = @"~\someFile.txt"; // Delete the file if it exists. AirDataAccess access = new AirDataAccess(); using (TextFieldParser parser = new TextFieldParser(path)) { parser.Delimiters = new string[] { "," }; while (true) { string[] words = parser.ReadFields(); if (words == null) break; else { AirData airData = http://stackoverflow.com/questions/15719066/null; if (words != null) { airData = new AirData(); airData.DateAired = Convert.ToDateTime(words[0]); if (adBusiness.isValidUniqueCode(airData.UniqueCode)) access.InsertAirData(airData); } } } } }\[/code\]here is myp page:\[code\] <asp:View ID="vUpload" runat="server"><aspanel ID="pnlUpload" runat="server" DefaultButton="btnUploadSave"><table border="0" cellpadding="5" cellspacing="0"><thead><tr> <td class="header">Upload a File</td> </tr></thead><tbody><tr> <td> <asp:RequiredFieldValidator ID="rfvUpload" runat="server" ErrorMessage="A file name is required" ControlToValidate="fuUpload" SetFocusOnError="true">* </asp:RequiredFieldValidator> <asp:FileUpload ID="fuUpload" runat="server" CssClass="button" Width="400px" /> </td></tr></tbody><tfoot><tr> <td align="right"> <asp:Button ID="btnUploadCancel" runat="server" CausesValidation="false" CssClass="button" Text="Cancel" UseSubmitBehavior="false" onclick="Cancel" /> <asp:Button ID="btnUploadSave" runat="server" CssClass="button" Text="Upload" onclick="btnUploadSave_Click" /> </td></tr></tfoot></table></aspanel></asp:View>\[/code\]