473,320 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Help with array

I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #1
12 1761
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0)); GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4... I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.

Nov 16 '05 #2
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0)); GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4... I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.

Nov 16 '05 #3
vbMark <no@email.com> wrote:
I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?


The easiest thing to do is avoid using the Array methods, and just use
the "normal" way of accessing arrays:

sFile = sArray[sArray.Length-1];

To correct your existing code, you could just add a cast to string
though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
vbMark <no@email.com> wrote:
I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?


The easiest thing to do is avoid using the Array methods, and just use
the "normal" way of accessing arrays:

sFile = sArray[sArray.Length-1];

To correct your existing code, you could just add a cast to string
though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hi,

Are you on a web app ? cause otherwise you have the incorrect / , it should
be \ .

and if all you need is get the name of the file you can do this ( if a win
app )
string file = System.IO.Path.GetFileName ( sFile );

Don't know if there is a "web" version though.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.

Nov 16 '05 #6
Hi,

Are you on a web app ? cause otherwise you have the incorrect / , it should
be \ .

and if all you need is get the name of the file you can do this ( if a win
app )
string file = System.IO.Path.GetFileName ( sFile );

Don't know if there is a "web" version though.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"vbMark" <no@email.com> wrote in message
news:Xn************************@130.133.1.4...
I'm tyring to extract the file name from a path entered in a text box by
doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'

I can't figure out how to correct this. Can someone help me here?

Thanks!

--
http://www.vbmark.com/
A good place to start.

Nov 16 '05 #7
"John Wood" <j@ro.com> wrote in news:Of**************@tk2msftngp13.phx.gbl:
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0));

GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.


Adding (string) did the trick. You lost me on the indexer thing.

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #8
"John Wood" <j@ro.com> wrote in news:Of**************@tk2msftngp13.phx.gbl:
sFile = (string)sArray.GetValue(sArray.GetUpperBound(0));

GetValue returns an object. Alternative you should use the indexer [] to
access the elements of the array in a type-safe manner.


Adding (string) did the trick. You lost me on the indexer thing.

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #9
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
vbMark <no@email.com> wrote:
I'm tyring to extract the file name from a path entered in a text box
by doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type
'object' to 'string'

I can't figure out how to correct this. Can someone help me here?


The easiest thing to do is avoid using the Array methods, and just use
the "normal" way of accessing arrays:

sFile = sArray[sArray.Length-1];

To correct your existing code, you could just add a cast to string
though.


Nice. Thanks.

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #10
Jon Skeet [C# MVP] <sk***@pobox.com> wrote in
news:MP************************@msnews.microsoft.c om:
vbMark <no@email.com> wrote:
I'm tyring to extract the file name from a path entered in a text box
by doing this:

string sFile = File1.Value;
string[] sArray = sFile.Split(new char[] {'/'});
sFile = sArray.GetValue(sArray.GetUpperBound(0));

However, I get the following error:
Compiler Error Message: CS0029: Cannot implicitly convert type
'object' to 'string'

I can't figure out how to correct this. Can someone help me here?


The easiest thing to do is avoid using the Array methods, and just use
the "normal" way of accessing arrays:

sFile = sArray[sArray.Length-1];

To correct your existing code, you could just add a cast to string
though.


Nice. Thanks.

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #11
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
wrote in news:#5*************@TK2MSFTNGP10.phx.gbl:
Hi,

Are you on a web app ? cause otherwise you have the incorrect / , it
should
be \ .

and if all you need is get the name of the file you can do this ( if
a win
app )
string file = System.IO.Path.GetFileName ( sFile );

Don't know if there is a "web" version though.

Cheers,


You're right, the / was incorrect.

I am doing this on an ASP page and GetFileName worked great.

Thanks!

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #12
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
wrote in news:#5*************@TK2MSFTNGP10.phx.gbl:
Hi,

Are you on a web app ? cause otherwise you have the incorrect / , it
should
be \ .

and if all you need is get the name of the file you can do this ( if
a win
app )
string file = System.IO.Path.GetFileName ( sFile );

Don't know if there is a "web" version though.

Cheers,


You're right, the / was incorrect.

I am doing this on an ASP page and GetFileName worked great.

Thanks!

--
http://www.vbmark.com/
A good place to start.
Nov 16 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Treetop | last post by:
I am creating a calendar with JavaScript. I want to be able to put date and time in an array and have a calendar display properly with 7 columns. I am stuck at this point. Any help would be...
3
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store...
7
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
5
by: ritchie | last post by:
Hi, I am writing to ask if anyone can see why my array is not being sorted correctly? It's an array of 4 elements(ints 1,2,3,4) but after calling the selection sort it comes back sorted as...
27
by: ruel loehr | last post by:
Hey guys, I am looking for some insight: Given two sorted arrays of integers A and B, where array B has enough extra room in it to hold the contents of both A and B. Merge array A and B...
3
by: ash | last post by:
Hey I am new, but I don't have time to intruduce myself yet. I am intro to C++ and this is a programme I have to write. all the direction are here, It will be very nice of someone to figure this...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: inkexit | last post by:
I need help figuring out what is wrong with my code. I posted here a few weeks ago with some code about creating self similar melodies in music. The coding style I'm being taught is apparently a...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.