Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

C# Files and Individual Folders (Hard to Explain)

files folders jgallery jquery asp.net c# images

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 noname111

noname111

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 79 posts

Posted 23 January 2014 - 01:13 AM

This is going to be very hard to explain so bare with me. I'm working with a jquery plugin called jgallery (http://jgallery.jakubkowalczyk.pl/) which is a fantastic piece of work. However, given the way the html is constructed I was going to generate the fields dynamically. On my web page this gallery will display files associated with each folder. The folders being the album names and all the files in the given album folders being tied to its parent. Which from there I would gather the information and generate it using jquery.

I have researched extensively and no results have had similar goals, but the most relevant directed me towards using System.IO.Directory. I have tried working with it using foreach loops, but it has resulted in blowing up in my face. I don't know how I am missing something that should be so simple. I would give more information but I'm so far lost that I have nothing.  :o 
Help in the right direction would be greatly appreciated and would save me hours beyond hours of frustration. I feel like I am gaining a history of asking stupid questions in this forum haha. :worry:



#2 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1065 posts

Posted 23 January 2014 - 06:08 AM

It sounds like you want to take a folder that is named according to the album that contains pictures?  e.g

[Folder] Flowers

     [File] Daisy.png

     [File] Tulip.png

     [File] Rose.png

 

From that you want generate html for use in the page.  I would use:

string [] subdirectoryEntries = Directory.GetDirectories(pathToDir); //To get directories such as Flowers, Mountains or whatever
string[] files = Directory.GetFiles(pathToFiles);//Get files like daisy.png, tulip.png

Then use a nested loop to go through each array and generate the html, which shouldnt be too hard.


There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#3 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 23 January 2014 - 08:25 PM

Could you give us a scope?

Like which folder do you want to work with, what does it have, and how do you want to work it?

System.....IO works great, you should just be missing some method, I am sure we can help if you could give us some specifics to work with.



#4 noname111

noname111

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 79 posts

Posted 25 January 2014 - 11:09 PM

It sounds like you want to take a folder that is named according to the album that contains pictures?  e.g

[Folder] Flowers

     [File] Daisy.png

     [File] Tulip.png

     [File] Rose.png

 

From that you want generate html for use in the page.  I would use:

string [] subdirectoryEntries = Directory.GetDirectories(pathToDir); //To get directories such as Flowers, Mountains or whatever
string[] files = Directory.GetFiles(pathToFiles);//Get files like daisy.png, tulip.png

Then use a nested loop to go through each array and generate the html, which shouldnt be too hard.

 

 

Thanks, I have run into the same stuff before and tried it only to fail. However, I remain persistent and believe it will work. I have a feeling I am missing something obvious.

 

 

 

Could you give us a scope?

Like which folder do you want to work with, what does it have, and how do you want to work it?

System.....IO works great, you should just be missing some method, I am sure we can help if you could give us some specifics to work with.

 

Sorry for the lack of information. I put it together when I was half awake and I am having trouble putting it into words as it is. But, I will explain it as best I can. I am currently working on setting up a photo gallery using the library I mentioned above. In its HTML structure it needs a <div> for each album and contains all of the photo links (<a> for the high quality photo and an <img> for the thumbnail) in addition to the title (which is stored in an <h1>). I currently have three folders, inside each folder is several images. I attach the local path to where the folders are located in a string for a reference. I intend on using the folder names as the album names, and inserting the photos to the appropriate albums (I'm going to have to find a way to sort the thumbnail images from the original images). I've been using javascript to access the array and create the HTML from there. If I missed something let me know. I'm still giving it a go.

Also, I really appreciate the help, despite my poor explanation.



#5 CommittedC0der

CommittedC0der

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1065 posts

Posted 26 January 2014 - 05:21 PM

Can you explain what exactly you can accomplish?  This shouldnt be too hard at all.

 

I suggest create a new console application and run this code to see how this works.

string filePath = "C:\\Path\\To\\Image\\";
string[] dirArray = Directory.GetDirectories(filePath);
foreach (string dir in dirArray)
{
   string[] files = Directory.GetFiles(dir);
   Console.WriteLine(dir.Substring(filePath.Length, dir.Length - filePath.Length));
   foreach (string file in files)
   {
       Console.WriteLine("     " + file);
   }           
}
Console.ReadLine();

Then all you need is to generate some html.

string html = "<div id=" + dir + "><h1>" + dir + "</h1>"; 

Edited by CommittedC0der, 26 January 2014 - 05:22 PM.

There IS a war going on for your mind.
Nothing of eternal significance happens besides prayer.

#6 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts

Posted 29 January 2014 - 09:29 PM

OK, then you might want to put all the information on the file name, like:

 

__PhotoAlbumNAME__SubFolder__PhotoNAME__t  

 

The t suffix would mean thumbnail, no t, no thumbnail

 


Edited by BlackRabbit, 29 January 2014 - 09:29 PM.