Click here to Skip to main content
15,867,885 members
Articles / Web Development / ASP.NET
Article

ASP.NET Deployment App

Rate me:
Please Sign up or sign in to vote.
3.21/5 (10 votes)
17 Aug 20043 min read 101.2K   1.1K   24   16
How I created an application to help exclude the many files needed to deploy a DotNetNuke site

Image 1

Introduction

I just became engrossed with the DotNetNuke Framework and have made a number of new modules to try out, but when it came time to upload the app -- provided I uploaded it all, it was over 60 Megs. That's a lot of time and transfer just for a bunch of unnecessary files. The best advice I had to strip out the unwanted files was to Search for them (in a copy) and delete them -- ONE PASS FOR EACH FILE. This was not going to do.

I did find another app that did what this one does with some extra features for zipping and ftping, but I was just looking for something to copy only the selected files and the existing folder structure to a new folder and I could deal with getting them up on the server myself.

The only snag in my plan was I didn't know exactly what file types were needed to fully support a DNN site. So I made the app scan the source folder for all the possible file extensions and then allow the user to uncheck the ones that shouldn't make the trip.

I didn't see anything else (besides the one mentioned earlier) that did this, so I thought I'd post it here for all to download.

Using the code

This is a very small little app -- only 7 methods. Let's get started.

Folder Browsing

First I needed a FolderBrowser Dialog (something I sorely missed with .net 1.0). Note the use of the Description attribute. Give the user something to read on the box.

C#
private void btnSource_Click(object sender, System.EventArgs e)
{
  folderBrowserDialog1.Description = 
    "Choose the Source Location to copy files from.";
  DialogResult result = folderBrowserDialog1.ShowDialog();
  if( result == DialogResult.OK )
  {
    tboxSource.Text = folderBrowserDialog1.SelectedPath;
  }
}
private void btnDestination_Click(object sender, System.EventArgs e)
{
  folderBrowserDialog1.Description = 
    "Choose the Destination Location to copy files to.";
  DialogResult result = folderBrowserDialog1.ShowDialog();
  if( result == DialogResult.OK )
  {
    tboxDestination.Text = folderBrowserDialog1.SelectedPath;
  }
}

I use a couple of textboxes to store the result -- or allow the user to just type them in.

Folder Checking

This routine, given a source and destination DirectoryInfo objects, iterates through the subfolders in the source and reiteratively calls itself to repeat the process, either making copies of all the folders and their subfolders if the site is being copied, or just allows the CheckFiles method to scan the files, but I get ahead of myself.

C#
private void CheckDirectories(DirectoryInfo source, 
  DirectoryInfo destination, bool Deploy)
{
  foreach (DirectoryInfo tempdir in source.GetDirectories())
  {
    if (Deploy)
    {
      destination.CreateSubdirectory(tempdir.Name);
      tboxCopiedFiles.Text += "Creating Folder " + 
       destination.FullName + "\\" + tempdir.Name + "\r\n";
      progressBar1.Increment(1);
    }
    //
    DirectoryInfo tSource = new DirectoryInfo(
      source.FullName + "\\" + tempdir.Name);
    DirectoryInfo tDestin = new DirectoryInfo(
      destination.FullName + "\\" + tempdir.Name);
    CheckDirectories(tSource, tDestin, Deploy);
    folderCount++;
    CheckFiles(tSource, tDestin, Deploy);
  }
}

File Checking

This next section either loads up the lboxExtensions listbox or actually does the file copying. It's simply a matter of making a FileInfo object for each thing the the directory and parsing out the extension or copying it to the destination.

C#
private void CheckFiles(DirectoryInfo source, 
   DirectoryInfo destination, bool Deploy)
{
  string extension = "";
  foreach (FileInfo tempfile in source.GetFiles())
  {
    extension = tempfile.Extension.ToLower();
    if (Deploy)
    {
      foreach (string item in lboxExtensions.CheckedItems)
      {
        if (item == extension)
        {
          tempfile.CopyTo(destination.FullName + "\\" + tempfile.Name, true);
          fileCount++;
          tboxCopiedFiles.Text += "Copying file " + tempfile.Name + "\r\n";
        }
      }
    }
    else
    {
      if (!lboxExtensions.Items.Contains(extension))
        lboxExtensions.Items.Add(extension, true);
    }
  }
}

Note:

I reused the Directory/File checking methods for both the scanning and the copying. I pass it the boolean mDeploy to control their behavior.

Button Clicking

I probably could have wrapped these into one EventHandler but -- I didn't do it. Sorry. A victim of RAD.

Pretty straight forward code here. Just a call to start the process (next -- finally!) and for working the ProgressBar.

C#
private void btnDeploy_Click(object sender, System.EventArgs e)
{
  progressBar1.Minimum = 0;
  progressBar1.Maximum = folderCount;
  this.StartProcessing(true);
  tboxCopiedFiles.Text += "Folders created: " +
    folderCount.ToString() + "\r\n";
  tboxCopiedFiles.Text += "Files copied: " + fileCount.ToString();
  progressBar1.Value = 0;
}

private void btnScan_Click(object sender, System.EventArgs e)
{
  this.StartProcessing(false);
  lboxExtensions.Sorted = true;
  this.btnDeploy.Enabled = true;
}

The Starting Point

I made this routine to be outside the reiterative process as a place to either start the Scan or the Deployment. It sets the button Enabling and kicks it all off. It also allows for one place for the try/catch block to be set. This method accepts the boolean mDeploy and passes that to the other methods.

C#
private void StartProcessing(bool mDeploy)
{
  this.btnDeploy.Enabled = false;
  this.btnScan.Enabled = false;
  tboxCopiedFiles.Text = "";
  try
  {
    DirectoryInfo srce = new DirectoryInfo(tboxSource.Text);
    DirectoryInfo dest = new DirectoryInfo(tboxDestination.Text);
    CheckDirectories(srce, dest, mDeploy);
    CheckFiles(srce, dest, mDeploy
  }
  catch (Exception ex)
  {
    MessageBox.Show("I/O Error", "Did you choose your folders?",
       MessageBoxButtons.OK);
  }
  if (this.lboxExtensions.Items.Count > 0)
    this.btnDeploy.Enabled = true;
  this.btnScan.Enabled = true;
}

Points of Interest

All in all a quick and easy project. Allowing me not to move fewer files up -- though I would still like to know exactly what files are needed. Emails on that subject are welcomed. This could easily be employed for a non-Website publishing purposes, but that's what I needed it for.

History

  • Version 1.0 completed : 8.9.2004

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionasp.net deployment...javascript errrors Pin
Manish Thapak3-Oct-07 5:29
Manish Thapak3-Oct-07 5:29 
GeneralModule deployment Pin
Russel Harvey1-Sep-04 12:15
Russel Harvey1-Sep-04 12:15 
GeneralRe: Module deployment Pin
bob_dotnet2-Sep-04 1:12
bob_dotnet2-Sep-04 1:12 
GeneralNice job, but... Pin
attackweasel18-Aug-04 9:27
attackweasel18-Aug-04 9:27 
GeneralRe: Nice job, but... Pin
bob_dotnet18-Aug-04 9:37
bob_dotnet18-Aug-04 9:37 
GeneralRe: Nice job, but... Pin
attackweasel18-Aug-04 9:57
attackweasel18-Aug-04 9:57 
GeneralModified Date Suggestion Pin
Trashken17-Aug-04 23:31
Trashken17-Aug-04 23:31 
GeneralRe: Modified Date Suggestion Pin
bob_dotnet18-Aug-04 1:19
bob_dotnet18-Aug-04 1:19 
GeneralSmall bug and a suggestion Pin
Stephane Lajoie14-Aug-04 15:48
Stephane Lajoie14-Aug-04 15:48 
GeneralRe: Small bug and a suggestion Pin
bob_dotnet16-Aug-04 1:22
bob_dotnet16-Aug-04 1:22 
GeneralRe: Small bug and a suggestion Pin
Stephane Lajoie16-Aug-04 2:08
Stephane Lajoie16-Aug-04 2:08 
GeneralRe: Small bug and a suggestion Pin
bob_dotnet16-Aug-04 2:14
bob_dotnet16-Aug-04 2:14 
QuestionExtensions to deploy? Pin
zoomba12-Aug-04 10:00
zoomba12-Aug-04 10:00 
AnswerRe: Extensions to deploy? Pin
bob_dotnet13-Aug-04 4:07
bob_dotnet13-Aug-04 4:07 
GeneralRe: Extensions to deploy? Pin
zoomba13-Aug-04 6:19
zoomba13-Aug-04 6:19 
GeneralRe: Extensions to deploy? Pin
tkraak8-Jan-05 7:01
tkraak8-Jan-05 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.