Visual Studio Project Woes

Project functions perfectly while Visual Studio is running, otherwise

Page 1 of 1

6 Replies - 853 Views - Last Post: 05 December 2009 - 04:38 PM Rate Topic: -----

#1 brennydoogles  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 23-June 09

Visual Studio Project Woes

Posted 25 November 2009 - 09:03 AM

Hello all, I am running into a puzzling issue that I think is Visual Studio related. I have a project that watches a particular folder on the hard drive, and performs a simple action when files are created in that folder. When run from Visual Studio (with or without debugging) the program works beautifully, but if run any other way the program runs but does not perform its intended function. I initially thought that maybe some required dlls were not being included in the project, but since the entire program only uses System, System.Windows.Forms, and System.IO everything should be included in .net. I have included the entire project so anyone can check my settings and see if this issue is able to be reproduced, and hopefully we will be able to figure out what I have done wrong. Thanks for the help all!
Attached File  WebcamCaptureRenamerGUI.zip (56.84K)
Number of downloads: 64

Is This A Good Question/Topic? 0
  • +

Replies To: Visual Studio Project Woes

#2 brennydoogles  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 23-June 09

Re: Visual Studio Project Woes

Posted 26 November 2009 - 08:50 AM

Polite bump.
Was This Post Helpful? 0
  • +
  • -

#3 brennydoogles  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 23-June 09

Re: Visual Studio Project Woes

Posted 02 December 2009 - 08:12 PM

One more polite bump.
Was This Post Helpful? 0
  • +
  • -

#4 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 525
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Visual Studio Project Woes

Posted 02 December 2009 - 08:26 PM

Well, you're using the FileSystemWatcher in System.IO?

(Sorry, haven't downloaded your zip so I'm just making some guesses)

So, there may be permission issues associated with it when ran outside of your IDE.

Can you elaborate on exactly how it is "run any other way"? It's pretty important information.
Was This Post Helpful? 0
  • +
  • -

#5 brennydoogles  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 23-June 09

Re: Visual Studio Project Woes

Posted 04 December 2009 - 12:01 PM

View PostMentalFloss, on 2 Dec, 2009 - 07:26 PM, said:

Well, you're using the FileSystemWatcher in System.IO?

(Sorry, haven't downloaded your zip so I'm just making some guesses)

So, there may be permission issues associated with it when ran outside of your IDE.

Can you elaborate on exactly how it is "run any other way"? It's pretty important information.


Well, If I attempt to publish the application (using Project->Build) I am able to generate an installer package, which I then install and run from the start menu. I have also attempted to run the project by explicitly running the .exe which is created when I build the project in release mode. When I run the program either of these ways, I get the tray icon for my program as I should, but the action that should be performed when I drop a file into the watched folder is not performed. I don't think it is a permissions issue, as the folder I am watching is located on my desktop and I am logged in. Here is the code for all functional components of the program:
using System;
using System.IO;
using System.Windows.Forms;

namespace WebcamCaptureRenamerGUI
{
	public partial class MainForm : Form
	{
		FileSystemWatcher dir;
		public MainForm()
		{
			InitializeComponent();
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			dir = new FileSystemWatcher();
			dir.IncludeSubdirectories = false;
			dir.Path = @"C:\Users\brendon\Desktop\Test";
			dir.Filter = "*.wmv";
			dir.Created += new FileSystemEventHandler(FileCreated);
			dir.EnableRaisingEvents = true;
		}

		protected void FileCreated(object sender, FileSystemEventArgs e)
		{
			FileInfo info = new FileInfo(e.FullPath);
			String oldName = e.Name;
			String newFileName = info.CreationTime.ToString("MMMM-dd-yyyy_HHmm") + info.Extension;
			try
			{
				String yearFolder = info.DirectoryName + @"\" + info.CreationTime.ToString("yyyy");
				String monthFolder = yearFolder + @"\" + info.CreationTime.ToString("MMMM");
				String dayFolder;
				switch (info.CreationTime.ToString("dd"))
				{
					case "1":
					case "01":
					case "21":
					case "31":
						dayFolder = monthFolder + @"\" + info.CreationTime.ToString("dd") + "st, " + info.CreationTime.ToString("dddd");
						break;
					case "2":
					case "02":
					case "22":
						dayFolder = monthFolder + @"\" + info.CreationTime.ToString("dd") + "nd, " + info.CreationTime.ToString("dddd");
						break;
					case "3":
					case "03":
					case "23":
						dayFolder = monthFolder + @"\" + info.CreationTime.ToString("dd") + "rd, " + info.CreationTime.ToString("dddd");
						break;

					default:
						dayFolder = monthFolder + @"\" + info.CreationTime.ToString("dd") + "th, " + info.CreationTime.ToString("dddd");
						break;
				}
				if (!Directory.Exists(yearFolder))
				{
					Directory.CreateDirectory(yearFolder);
				}
				if (!Directory.Exists(monthFolder))
				{
					Directory.CreateDirectory(monthFolder);
				}
				if (!Directory.Exists(dayFolder))
				{
					Directory.CreateDirectory(dayFolder);
				}
				String newFile = Path.Combine(dayFolder, newFileName);
				if (info.FullName != newFile)
				{
					info.MoveTo(newFile);
				}
			}
			catch (Exception error)
			{
				MessageBox.Show(error.Message);
			}
		}


		private void MainForm_Resize(object sender, EventArgs e)
		{
			if (FormWindowState.Minimized == WindowState)
				Hide();
		}

		private void notifyIcon1_DoubleClick(object sender, EventArgs e)
		{
			//Show();
			//WindowState = FormWindowState.Normal;
		}

		private void exitToolStripMenuItem_Click(object sender, EventArgs e)
		{
			this.Close();
		}

		private void MainForm_Shown(object sender, EventArgs e)
		{
			this.Hide();
		}
	}
}



Any help would be greatly appreciated!
Was This Post Helpful? 0
  • +
  • -

#6 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 525
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Visual Studio Project Woes

Posted 05 December 2009 - 03:24 AM

Do you run your installer by right clicking and selecting Run As Administrator?

I still think it's permission issue but I suggest you just modify your code to register to every event that FileSystemWatcher works with. I say this because your action might not trigger the file created event.

Ex:
			dir.Created += new FileSystemEventHandler(FileCreated);
			dir.Changed += FileCreated;
			dir.Deleted += FileCreated;
			dir.Renamed += FileCreated;



Second to that, I'd say add an App.config file and store the path to your watcher. So instead of hard-coding it, you can modify it. This way you can install it, and modify your app.config a bit to point to different areas and test it further.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<appSettings>
		<add key="WatchPath" value=""/>
	</appSettings>
</configuration>



Then in code, access it like this:

	// Use System.Configuration for this. May have to add reference.
	public static class AppSettingsRetriever {

		public static string WatchPath {
			get {
				return System.Configuration.ConfigurationManager.AppSettings["WatchPath"];
			}
		}
	}



So, your mainform load becomes:

private void MainForm_Load(object sender, EventArgs e) {
			dir = new FileSystemWatcher();
			dir.IncludeSubdirectories = false;
			dir.Path = AppSettingsRetriever.WatchPath;
			dir.Filter = "*.wmv";
			dir.Created += new FileSystemEventHandler(FileCreated);
			...



Now, one more thing you can try is to remove the watcher's filter. Then you can identify whether it's a permissions issue or the filter. But regardless, your path should be in a config file

Hope this helps.
Was This Post Helpful? 1
  • +
  • -

#7 brennydoogles  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 59
  • Joined: 23-June 09

Re: Visual Studio Project Woes

Posted 05 December 2009 - 04:38 PM

Ok, so I have at least made some headway. I created a new project in Visual Studio and basically redid the whole project. It appears that the installer created by VS may have been quite a bit of the problem. I created a new installer using Excelsior installer, and it runs great. I also went ahead and added the App.config file, because I was already considering externalizing the path for ease of distribution later. I'm not sure what the problem was before, but now that I have a workable solution... I guess it doesn't matter too much. Thank you so much for your help!

P.S.-- If anyone would like to see the finished product feel free to let me know and I'll toss it up here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1