tags:

views:

24

answers:

1

I have a problem with my code. My code is using the fileupload control to browse for a filename when you add a filename it processes it and the code runs fine on when it lives on local host, but when I put the code on our prodution server it cannot find the filenames listed by user.

For example if I use the upload control to browse to B:\MIS\CH Intive\RPTTOFL_3.csv and the code lives on my localhost which know what that file path means it works, but if the code is moved to a production server it may or maynot know what B:/ is or B:/ maybe mapped to something else. Even if I am browsing to a file on my C drive it will work on if the code is on the machine that the C drive is on, but it will not work if the code is on another machine because obviously that file wouldnt be on that C drive.

Private Function CSV2DataTable(ByVal filename As String) As DataTable

Using MyReader As New  _
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
            MyReader.TextFieldType = FileIO.FieldType.Delimited

.
.
.

What can I do in asp.net to make the filename work correctly?

Ok lets say I get the filename and save it as so

FileUploadControl.SaveAs(Server.MapPath("~/") + filename);

now I want to pass the filename to the function above for processing. Do I pass Server.MapPath("~/") + filename as the filename? Also when I am done what do I do to delete the file from the server?

+1  A: 

It seems that you are mixing the client and server locations of the file. Before reading the uploaded file, the server-side code must save it on the server (client-side file location is mostly irrelevant at this point). From VS help on FileUpload class: "The code that you write to save the specified file should call the SaveAs method, which saves the contents of a file to a specified path on the server." The online help topic on FileUpload control has enough information (with examples) to achieve what you need.

Igor
Can you point me to a good one with the code I am looking for?
Nick LaMarca
I need to be able to pass the filename to a function. How would I do that?
Nick LaMarca
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx - as you will see from the examples there, you completely control the location on the server where you save the uploaded file, therefore after saving the file on the server you know its full path to pass to a function.
Igor