dodgerfan
asked on
Server.MapPath and new folders
I'm using Server.Mappath to return some images and display them in a datalist. The file that stores the images was going to just be the Images folder in my solition. Now before I create and store the images, I'm creating a new folder under the images folder. Everything works except when it goes to display the images it no longer knows where to look. Any idea how to fix this?
dlImages.DataSource = System.IO.Directory.GetFil es(Server. MapPath("~ /Images/") );
dlImages.DataBind();
The new folder is created in the code preceding this, so there is a variable I can work with. How can I get it to look for the newly created folder, which will change all of the time based on what was just created?
This did not work:
dlImages.DataSource = System.IO.Directory.GetFil es(Server. MapPath("~ /Images/" + newFolder));
Any help is appreciated.
dlImages.DataSource = System.IO.Directory.GetFil
dlImages.DataBind();
The new folder is created in the code preceding this, so there is a variable I can work with. How can I get it to look for the newly created folder, which will change all of the time based on what was just created?
This did not work:
dlImages.DataSource = System.IO.Directory.GetFil
Any help is appreciated.
Can you show how "newFolder" was created? Seems like you have a problem with the slashes of paths. If newFolder is a whole path, or if it starts out with a slash, you need a different approach.
ASKER
I've attached my complete function in a code snippet. I'm using Aspose slides for some of this.
Label2.text = "File Uploaded: " + hiddenValue;
string newPath = System.IO.Path.GetFileNameWithoutExtension(hiddenValue.Value);
string thumbnailPath = System.ConfigurationManager.AppSettings["uploads"];
Directory.CreateDirectory(thumbnailPath + newPath);
string FinalPath = thumbnailPath + newPath + "/";
Presentation srcPres = new Presentation(uploadPath + hiddenValue.Value);
int lastSlidePostion = srcPres.Slides.LastSlidePosition;
for (int i=1; i<= lastSlidePosition; i++)
{
Slide sld = srcPres.GetSlideByPosition(i);
double scaleX = 1.3;
double scaleY = 1.3;
System.Drawing.Image img = sld.GetThumbnail(scaleX, scaleY);
img.Save(String.Concat(finalPath, "Slide_", i.ToString().PadLeft(2, '0'), ".jpeg"), ImageFormat.Jpeg);
}
dlImages.DataSource = System.IO.Directory.GetFiles(Server.MapPath("~/Images/"));
dlImages.DataBind();
you are creating new folder in "thumbnailPath" and trying to access it in "images" folder are they both pointing to same location ? If yes then no need to use "Server.MapPath" as u have same path in string FinalPath = thumbnailPath + newPath + "/";
ASKER
I've tried using finalPath like this:
dlImages.DataSource = System.IO.Directory.GetFil es(Server. MapPath(fi nalPath);
It does not work. My datalist on the html page is below. The images/ is wrong now, correct? How do I fix that?
<asp:datalist id="dlImage" runat="server" RepeatDirection="Vertical" >
<ItemTemplate>
<a href='<%= ResloveUrl("~/")images/<%# GetFileName(Container.Data Item.ToStr ing()) %>' target="main">
<img src='<%= ResloveUrl("~/")images/<%# GetFileName(Container.Data Item.ToStr ing()) %>' alt="Image" height="150" width="150" border="0" />
</a>
</ItemTemplate>
</asp:DataList>
dlImages.DataSource = System.IO.Directory.GetFil
It does not work. My datalist on the html page is below. The images/ is wrong now, correct? How do I fix that?
<asp:datalist id="dlImage" runat="server" RepeatDirection="Vertical"
<ItemTemplate>
<a href='<%= ResloveUrl("~/")images/<%#
<img src='<%= ResloveUrl("~/")images/<%#
</a>
</ItemTemplate>
</asp:DataList>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
abel, thanks for the insight and help. A lot of the code at this point is a work in progress as I try different things to get it working again. I have tried your suggestion before about the dlImages.DataSoure = System.IO.Directory.GetFil es(finalPa th);
It does not work for some reson. Is there something else I should try?
It does not work for some reson. Is there something else I should try?
ASKER
Go it. Had to remove ResloveUrl from the html page calling the datalist. thanks.
> Go it. Had to remove ResloveUrl from the html page calling the datalist. thanks.
Good, glad you got it working in the end
Good, glad you got it working in the end