Click here to Skip to main content
11,478,902 members (59,538 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
can someone tell that how to remove this error from my code my ,code is :--

f = file.FileName;
if (!string.IsNullOrEmpty(f))
{
    f1 = adcode;
    f  = f.Substring(f.LastIndexOf("."));
    f1 = "~/images/" + f1 + f;

Pls some tell, on adcode, throwing an error.
Posted 23-Apr-11 0:16am
Edited 23-Apr-11 0:44am
v2
Comments
santosh dhanawade at 23-Apr-11 5:34am
   
Which error,
And what is datatype of f1
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

line cannot implicitly convert type 'int' to 'string' in asp.net c# heared so many time,

You have to do following things,

f1= Convert.ToString(abcode);

or

f1=adcode.ToString();
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

For converting to string use Convert.ToString method or ToString() method (every object has one!).
For converting from string to some numeric value use Parse or TryParse method of particular type.

For anything else, take Santosh's advice. Read MSDN about type casting.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hey if abcode is integer then you should used
const int abcode= -273;
   f1 = Convert.ToString(abcode);
Please read MSDN for more information of type casting
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

What type is the variable abcode?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

You can try

f1 = Convert.ToString(abcode);

This can be use full.

Hope this can help you.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

I'm a fan of the String.Format method. This will take any object and call it's ToString method for you, then apply it to your specified string along with any other formatting (if you so choose).

f = file.FileName; 
if (!string.IsNullOrEmpty(f)) 
{ 
    f1 = String.Format("~/images/{0}{1}", adcode, f.Substring(f.LastIndexOf(".")));
}

More info here: http://msdn.microsoft.com/en-us/library/system.string.format.aspx[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

chander_rani wrote:
f = file.FileName;
if (!string.IsNullOrEmpty(f))
{
f1 = adcode;
f = f.Substring(f.LastIndexOf("."));
f1 = "~/images/" + f1 + f;


I see that f is a string but on the part of f1 there is no other code to support if f1 is the integer and adcode the string or if adcode the integer and f1 the string, so the solution can go a few different ways.

if f1 is an integer and adcode is an integer then f1=adcode; is correct but f1 = "~/images/" + f1 + f; is incorrect because "/images/" cannot be converted to integer

if f1 is string and adcode is an integer then f1=adcode would be incorrect and to fix this just call as f1=adcode.ToString(); and f1 ="~/images/" + f1 + f; would display correctly.

if f1 is an integer and adcode is a string then it's all wrong. first only if adcode is equal to an integer example adcode="10"; could you call f1=adcode but it would have to be called as f1=Int32.Parse(adcode); and second f1="~/images/" + f1 + f; could not be called because "/images/" is not convertable to an integer.
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

write it as f1 = "abcode"; or if abcode is an integer then use it as abcode.ToString()
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 195
1 F-ES Sitecore 170
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,865
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,059
3 Maciej Los 2,491
4 Richard Deeming 2,335


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 25 Apr 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100