471,319 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

.Split a directory string

I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);

Dec 28 '05 #1
4 7434
Try using this:

string strFileNameOnServer = txtServername.Value;
char[] sep = {'\\'};
string[] a = strFileNameOnServer.Split(sep);

--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"merrittr" <me******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);

Dec 28 '05 #2
Hello merrittr,

Why not to use
string fileName = @"C:\mydir\myfile.ext";
string path = @"C:\mydir\";
string result;
result = Path.GetFileName(fileName);

instead of splitting ?

m> I have a string "c:\upload\file.txt"
m> what I want is the file name to do this I was trying split on \ but
m> I cant seem to get it to work?

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Dec 28 '05 #3

"Christopher Reed" <ca****@nospam.nospam> wrote in message
news:O7**************@tk2msftngp13.phx.gbl...
Try using this:

string strFileNameOnServer = txtServername.Value;
char[] sep = {'\\'};
string[] a = strFileNameOnServer.Split(sep);

--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"merrittr" <me******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a string "c:\upload\file.txt"
what I want is the file name to do this I was trying split on \ but
I cant seem to get it to work?
Server Error in '/appform' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: CS1502: The best overloaded method match for
'string.Split(params char[])' has some invalid arguments

Source Error:

Line 234: string strFileNameOnServer = txtServername.Value;
Line 235: string sep = @"\";
Line 236: Array a = strFileNameOnServer.Split(sep);



I prefer to let the framework do the "heavy lifting". Check out the
System.IO.Path class:

using System;
using System.Diagnostics;
using System.IO;

void SomeFunction()
{
string filePath = @"C:\SomeFolder\file.txt";
string fileName = Path.GetFileName(filePath);
Debug.WriteLine(fileName); // prints "file.txt"
}
Dec 28 '05 #4
whoaaa that was fast
this works perfectly thanks for the help guys

Dec 28 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Stu Cazzo | last post: by
12 posts views Thread by Martin Dieringer | last post: by
1 post views Thread by porterboy76 | last post: by
4 posts views Thread by Itzik | last post: by
3 posts views Thread by Stephan Bour | last post: by
5 posts views Thread by kurt sune | last post: by
reply views Thread by rosydwin | last post: by

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.