473,511 Members | 15,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1766
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
1936
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
1927
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
3570
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
2190
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
2314
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
3804
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
10685
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
3721
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
6278
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
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7508
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...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4737
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
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1572
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 ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.