Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7824823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:43:35+00:00 2026-06-02T08:43:35+00:00

I have a PHP script which I am trying to convert to ASP.NET C#

  • 0

I have a PHP script which I am trying to convert to ASP.NET C#

Here is the PHP:

<?php

/* Configuration Start */

$thumb_directory = 'img/thumbs';
$orig_directory = 'img/original';

$stage_width=600;   // How big is the area the images are scattered on
$stage_height=400;

/* Configuration end */

$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;

/* Opening the thumbnail directory and looping through all the thumbs: */

$dir_handle = @opendir($thumb_directory) or die("There is an error with your image directory!");

$i=1;
while ($file = readdir($dir_handle)) 
{
    /* Skipping the system files: */
    if($file=='.' || $file == '..') continue;

    $file_parts = explode('.',$file);
    $ext = strtolower(array_pop($file_parts));

    /* Using the file name (withouth the extension) as a image title: */
    $title = implode('.',$file_parts);
    $title = htmlspecialchars($title);

    /* If the file extension is allowed: */ 
    if(in_array($ext,$allowed_types))
    {
        /* Generating random values for the position and rotation: */
        $left=rand(0,$stage_width);
        $top=rand(0,400);
        $rot = rand(-40,40);

        if($top>$stage_height-130 && $left > $stage_width-230)
        {
            /* Prevent the images from hiding the drop box */
            $top-=120+130;
            $left-=230;
        }

        /* Outputting each image: */

        echo '
        <div id="pic-'.($i++).'" class="pic" style="top:'.$top.'px;left:'.$left.'px;background:url('.$thumb_directory.'/'.$file.') no-repeat 50% 50%; -moz-transform:rotate('.$rot.'deg); -webkit-transform:rotate('.$rot.'deg);">
        <a class="fancybox" rel="fncbx" href="'.$orig_directory.'/'.$file.'" target="_blank">'.$title.'</a>
        </div>';
    }
}

/* Closing the directory */
closedir($dir_handle);

?>

I am struggling to get the array part working. Is the PHP setting up an array called file_parts? Does this mean I have enumerate the directory in ASP.NET?

This is what I have tried so far, still work in progress:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class web_content_notes_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        /* Configuration Start */
        string thumb_directory;
        string orig_directory;

        thumb_directory = ("img/thumbs");  
        orig_directory = ("img/original");

        // How big is the area the images are scattered on
        int stage_width;
        int stage_height;
        stage_width = 600;
        stage_height = 400;
        /* Configuration end */


        // array of allowed file type extensions
        string[] allowed_types = { "bmp", "gif", "png", "jpg", "jpeg", "doc", "xls" };

        //declare the array
        string[] file_parts;
        string ext = "";
        string title = "";

        int i = 0;

        /* Opening the thumbnail directory and looping through all the thumbs: */
        string dir_handle;
        dir_handle = thumb_directory;

        string file;


        while (file = dir_handle);
        {
            Console.WriteLine(file_parts[i]);
        }


     //.....


    }
}

How do I loop through the array? bit confused as the array isn’t filled until the directory is read.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:43:36+00:00Added an answer on June 2, 2026 at 8:43 am

    You can use the System.IO.Directory‘s GetFiles method (MSDN) to achieve this;

    for (string file in System.IO.Directory.GetFiles(thumb_directory)) {
      Console.WriteLine(file);
    }
    

    It’ll be worth having a look at the System.IO.Path class (MSDN) as it gives you some nice methods like GetFileNameWithoutExtension() and GetExtension().

    Edit: Full conversion;

        protected void Page_Load(object sender, EventArgs e) {
            /* Configuration Start */
            string thumb_directory = "img/thumbs";
            string orig_directory = "img/original";
            int stage_width = 600;
            int stage_height = 480;
            Random random = new Random();
    
            // array of allowed file type extensions
            string[] allowed_types = { "bmp", "gif", "png", "jpg", "jpeg", "doc", "xls" };
    
            /* Opening the thumbnail directory and looping through all the thumbs: */
            foreach (string file in Directory.GetFiles(thumb_directory)) {
                string title = Path.GetFileNameWithoutExtension(file);
                if (allowed_types.Contains(Path.GetExtension(file)) == true) {
                    int left = random.Next(0, stage_width);
                    int top = random.Next(0, 400);
                    int rotation = random.Next(-40, -40);
    
                    if ((top > stage_height - 130) && (left > stage_width - 230)) {
                        top -= 120 + 130;
                        left -= 230;
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here I have a simple php script which displays some values from a database
I have a script in which I am trying to load a custom php.ini
I have this PHP script which i'm grabbing images from a directory and displaying
I have a php script which saves the original image, then resizes it -
I have a PHP script which creates and listens on a port for connections
I have a PHP script which is generating buttons to each content schedule. The
I have a PHP search script which I've altered slightly and works well for
I have a php script (generator.php) which generates certain HTML/XML/SVG depending on various conditions.
I have a PHP script (news-generator.php) which, when I include it, grabs a bunch
I have a PHP-script originally developed on Ubuntu, which now has to run on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.