Concatanating server side tags in markup

Posted by Fjameel under ASP.NET on 9/9/2009 | Views : 1564 | Status : [Member] | Replies : 3
I am trying to pass a Filename from server side to a XmlDatasource ...

This works
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile='~/DataFiles/test.xml' XPath="/ITEMS/item"></asp:XmlDataSource>

However passing the file name from server side always results in the error "Illegal characters in the path"

Have tried the following

asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile='<%=FullPath %>' XPath="/ITEMS/item"></asp:XmlDataSource>
asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile='~/DataFiles/<%=FileName %>' XPath="/ITEMS/item"></asp:XmlDataSource>
asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/DataFiles/'<%=FileName %>'" XPath="/ITEMS/item"></asp:XmlDataSource>

Any suggestions




Responses

Posted by: Raja on: 9/9/2009 [Member] Starter

Up
0
Down
Hi

Why don't you try writing like below in code behind.

XmlDataSource1.DataFile = "~/DataFiles/test.xml"


and I am sure, this will work.

Thanks

Regards,
Raja, USA

Fjameel, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/10/2009 [Member] [MVP] Bronze

Up
0
Down
In the codebehind you can set it like

XmlDataSource1.DataFile = "~/DataFile/someFile.xml";

I think you will need to do this in the DataBinding event of the XmlDataSource:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource_events.aspx

Fjameel, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/10/2009 [Member] [MVP] Bronze

Up
0
Down
Sorry raja I didnt see your reply before I posted!

We have basically said the same thing :)

Fjameel, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response