Hey y'all,
I am uploading a file to a directory in my root named "Pictures" and it works fine.
I also add a title , url, and name of the picture in a XmlDatasource, and this works fine.
In my masterPage.master file I have;
[div id="image-area"]
[a id="linkPart" runat="server" href="http://www.pic_site.com]
[img id="imagePart" runat="server" src="pictures/pic.jpg" alt="Image of the Day" /][/a]
[p id="captionPart" runat="server">The rules according to Luna[/p]
[/div]
Note: As this is my first post I have replaced the "<>" with "[]" just in case no handled!
And in my masterPage.master.cs code behind file I have;
XmlNode elem = GetRandomPictureNode();
linkPart.HRef = elem.SelectSingleNode("url").InnerText;
str = elem.SelectSingleNode("file").InnerText;
string path = Server.MapPath("~/pictures/");
imagePart.Src = path + str;
captionPart.InnerText = elem.SelectSingleNode("title").InnerText;
The value that gets put into .Src is correct but the image doesn't display I get the alt "Image of the Day" instead?
P.S. The link and title work fine its just the image that doesn't work!
What the heck have I overlooked or don't understand?
Any help appreciated!
Mike
Loading
Mike HankeyPosted Apr 23, 2008, 11:17 PM
I have the MapPath in my PageLoad method of the masterPage.master.cs code behind file.
What you suggested did not work, but I found that if I use;
string path = "pictures/";
imagePart.Src = path + str;
captionPart.InnerText = elem.SelectSingleNode("title").InnerText;
that it works but I am stumped why the MapPath doesn't work? According to the research I did on it, which was considerable (always like to research before I ask questions) that the MapPath maps virtual directory to physical.
When I debugged the str pointed to the correct physical drectory and file but would not diplay the image?
Thanks,
Mike
Scott LyslePosted Apr 23, 2008, 10:54 PM
Mike:
Where you have: string path = Server.MapPath("~/pictures/");
Try this instead: Server.MapPath("~\Pictures\"