473,473 Members | 4,208 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to introduce an escape character in filepath...???

9 New Member
hi..
i am trying to pass the file path of a text file, which i need to read, to a file object so as to read all lines of the text file. and i am selecting the file through a filedialog and i obtained the filepath and the filename using the FileName and SafefileName properties of the filedialog ...as:

now i am facing problem in introducing the escape character to ignore the backslash punctuation while passing the filename in a string variable.

for understanding of the problem my code is like:




*********obtaining the filename from filedialog property.
filepath = dialogbox.FileName;
filename = dialogbox.SafeFileName;

*********here i am passing the filepath obtained above into the file object to read lines from it.
string[] lines = File.ReadAllLines(filepath);


consider my filepath is like:
C:\Myfiles\abc.txt

now i want to introduce the escape character to the filepath string to make it like:
@"C:\Myfiles\abc.txt"
or
C:\\Myfiles\\abc.txt


so that i can pass this filepath string to the file object as shown above.


any idea would be very helpful..thanks a lot in advance..
Jul 30 '10 #1
2 5755
Joseph Martell
198 Recognized Expert New Member
You shouldn't need to use any escape sequences. Escape sequences are for the compiler, not for the actual runtime. We use stuff like a \\ to tell the compiler to insert the appropriate character into the string in memory. The first \ character is not maintained in memory. It is just a direction to the compiler. From wikipedia:

"There are usually two functions of escape sequences. The first is to encode a syntactic entity, such as device commands or special data which cannot be directly represented by the alphabet. The second use, referred to as character quoting, is to represent characters which cannot be typed in current context, or would have there an undesired interpretation."

Again, escape sequences are directions for the compiler to use certain values that either we can't type or would be difficult to interpret correctly. At runtime, such directions aren't necessary.
Jul 30 '10 #2
indona
9 New Member
thanks a lot.. it worked..
Aug 1 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Alden Streeter | last post by:
Here is the HTML that is being output by my asp page: <a href='Files/category/computers/bigimages/computers-sub-monitors.jpg' target='_blank' onMouseOver="window.status='Click for a larger image...
1
by: Grant Allen | last post by:
I know this has been asked before - I've trawled through the mail archives and FAQs looking for any info, and only found "that's the way it works" answers. Basically, I want to turn off backslash...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
3
by: newsgroupie | last post by:
Hi Newsgroupies, Please could someone tell me the escape character for " (double quote) in a string.Format(...) method as \x22 doesn't work as it comes out as \" in the result. i.e....
7
by: Steve | last post by:
string str ="\"C:\Program Files\Internet Explorer\iexplore.exe\" -nohome" How can I remove charcter to string str = ="C:\Program Files\Internet Explorer\iexplore.exe -nohome"
3
by: Steve | last post by:
The string in registry is "rundll32.exe C:\Program Files\INTERN~1\hmmapi.dll,OpenInboxHandler" After opensubkey and getregistry, I got "rundll32.exe \"C:\\Program...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
6
by: HK guy | last post by:
In C#, it has a escape chatacter @ then can ingnore all the escape charactrer in string, how about in VB.NET, any escape character like @? Thank you
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
3
by: slomo | last post by:
How to read strings cantaining escape character from a file and use it as escape sequences? for example, a file 'unicodes.txt' has contents: \u0050\u0079\u0074\u0068\u006f\u006e Now, ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.