Weird file path problem with C#

Associate
Joined
18 Oct 2002
Posts
972
Location
Derby
Hi there.

I am currently working on a upload script that works with session variables. It is basically so users can upload pdf files to relevant folders in a house buying/selling system. An example if

User A has a PDF document from the site "king street", all the relevant information is in the session.

The location is a folder called "Sites" and inside there is the "king street" folder along with all others.

What I want to do if upload the PDF to the \\Drive\Sites\(relevant session)\file.pdf however in c# it decided to take my path and add a character to it which of course crashes the compiler.

So instead of this:

\\Drive\Sites\king street\file.pdf

I get

\\Drive\Sites\ king street\file.pdf

Here is my map string, any help really appreciated.

Code:
  y.SaveAs(HttpContext.Current.Server.MapPath("C:\\" + sessionSiteName+ sessionFileNumber + folder + sessionFileNumber + dash + sessionPlotDealer + fileExtension));

In the code "folder" is = "\\" and "dash" is = "-"
 
i'd try building that string into a string object first and then checking that in the debugger.

I suspect that one or more of your variables has gained an extra training / leading space.

Paul
 
happytechie said:
i'd try building that string into a string object first and then checking that in the debugger.

I suspect that one or more of your variables has gained an extra training / leading space.

Paul

Not 100% what you mean there but I have done a response.write and got a different result.

I now get: T:\Plots\PlotData\King Street\ 2\ 2- .pdf

This is on a page were "King Street" was already in the session. The rest of the data is then added to the session on this page. I am adding the data through your usual asp:Textbox, really weird problem that I have never had before this one is.
 
Thanks for your help happytechie but I got it working using String.Trim(). BTW you have been around a while, i remember getting some getting oracle help off you about 3-4 years ago.
 
You dont need the escape characters for the filename if you use the @ sign before the string i.e. I find it makes things easier to read.

Code:
textBox1.Text = "c:\\test\\test2\\test3"

is the same as:-

Code:
textBox1.Text = @"c:\test\test2\test3"
 
Back
Top Bottom