Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSetting the ImageUrl on asp:image controlSetting the ImageUrl on asp:image control
Previous
 
Next
New Post
6/9/2010 2:03 PM
 
Seems like an easy task but I can't seem to make it work. I am creating a simple module that will display random images from the gallery module. All I have is a web user control with an asp:image control ID="Image1"
In the Page_Load I have this:
            Random randomGenerator = new Random();
            DirectoryInfo di = new DirectoryInfo(Server.MapPath(".") + "/Portals/0/Gallery/377/_source/");
            FileInfo[] fi = di.GetFiles("*.jpg");
            int fileNumberToUse = randomGenerator.Next(1, fi.Length + 1);
            int fileLoop = 1;
            foreach (FileInfo picFile in fi)
            {
                if (fileLoop == fileNumberToUse)
                {
                    Image1.ImageUrl = di.ToString() + "/" + picFile.ToString();
                    Image1.AlternateText = picFile.ToString();
                }
                fileLoop++;
            }

What I get is a box where the image should be that has an image icon and the alt text of the image name.
Anybody know why it won't display the image instead of just it's name?
 
New Post
6/10/2010 1:07 AM
 
Hover over the missing image icon with your mouse pointer, right click, select properties, and take a close look at the actual url for the image. You'll see that it is not a valid url and should have a good idea where the errors in you code are located. I would also suggest rewriting the code to avoid the for each loop for better efficiency.

Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
6/10/2010 2:29 PM
 
Thanks William,
Your right, it has to be a virtual path for the ImageUrl.
I got this to at least show the image.

     Random randomGenerator = new Random();
     DirectoryInfo di = new DirectoryInfo("f:/Web/dnn/hrr/Portals/0/Gallery/395/_source");
     FileInfo[] picFiles = di.GetFiles("*.jpg");
     int fileNumberToUse = randomGenerator.Next(1, picFiles.Length + 1);
     int fileLoop = 1;
     foreach (FileInfo fi in picFiles)
     {
         if (fileLoop == fileNumberToUse)
         {  
             Image1.ImageUrl = Request.ApplicationPath + "Portals/0/Gallery/395/_source/" + fi.ToString(); 
            break;
        } 
        fileLoop++; 
    }

A bit crude yet but at least I am seeing the random image.

Thanks,
Marty
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesSetting the ImageUrl on asp:image controlSetting the ImageUrl on asp:image control


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out