Click to See Complete Forum and Search --> : Error generating html at runtime


mharley
March 2nd, 2007, 02:33 PM
I am trying to build an html link in a function and return the html. I keep getting an error, however, and I can't see the cause. The code is as follows:

return "<a href=''gallery.aspx?page=1&subpage=" + inSubpageSlash.Replace(" ", "%20") + Path.GetFileName(s.Replace(" ", "%20")) + "''><img width=125 height=93 src=''images/Folder.jpg'' border='0'></a><br>" + "<div align=center><span style=''font size:'8pt'; font-family:'Verdana';''>" + Path.GetFileName(s) + "<br>" + dirsIn.GetLength + " directories<br>" + filesIn.GetLength & " images<br></span></div>";

This produces the following error:

Operator '+' cannot be applied to operands of type 'string' and 'method group'

This piece of the above code is singled out:

<a href=''gallery.aspx?page=1&subpage="

I can't see the problem, which means that it's probably something simple that I'm overlooking. Any thoughts?

mcmcom
March 2nd, 2007, 04:11 PM
the problem is your trying to concatenate a string and a method.

you should try this :
return "<a href=''gallery.aspx?page=1&subpage=" + (inSubpageSlash.Replace(" ", "%20")) + Path.GetFileName(s.Replace(" ", "%20")) + "''><img width=125 height=93 src=''images/Folder.jpg'' border='0'></a><br>" + "<div align=center><span style=''font size:'8pt'; font-family:'Verdana';''>" + Path.GetFileName(s) + "<br>" + dirsIn.GetLength + " directories<br>" + filesIn.GetLength & " images<br></span></div>";

if that doesn't work use the method to return a temp string and concatenate that.

hth,
mcm

mharley
March 5th, 2007, 01:56 PM
I'm afraid that I'm still not having any luck. I've tried breaking the line into smaller strings and concatenating those, but there was no change. The following bit seems to be the cause of all the grief:

"<a href=gallery.aspx?page=1&subpage="

I don't understand what it is about this piece that the compiler doesn't like. It is still throwing the 'Operator '+' cannot be applied to operands of type string and method group' error.

mcmcom
March 5th, 2007, 04:17 PM
all your methods in that string need to be encapsulated in new ( )'s
because while they may return a string they are not concatenating right.

Option 1. Make string variables form your methods before you call this code
like
string filename = Path.GetFileName(s.Replace(" ", "%20"))
string fn2 = Path.GetFileName(s);

then concatenate your string liek "mything1" + mything2 + filename + fn2, etc.

Option 2:

Encompass ALL Method calls in brackets
like:
Path.GetFileName(s) should be (Path.GetFileName(s));
dirsIn.GetLength <- IF THIS IS A METHOD (dirsIn.GetLength());
Path.GetFileName(s.Replace(" ", "%20")) should be (Path.GetFileName(s.Replace(" ", "%20")));

hth,
mcm

AlanGRutter
March 5th, 2007, 04:25 PM
Looking on Google, this error seems to imply that you are either trying to call a function that doesn't return a string or you are trying to call what looks like a function without the ().

Looking at your line of code, I think you need to break it up into individual pieces (at each +) and see which bits work.

I notice that you use GetLength which to me looks like a function - do you need to add () to it. It also returns an integer - do you need to turn this into a string or is it automatic.

Regards
Alan

mcmcom
March 5th, 2007, 04:34 PM
ya i was thinking that as well.

Best course of action for debugging. Take all method calls and put them into individual strings and debug your code, you will see which ones are turning into (returning) strings and which ones are not.

hth,
mcm