Click here to Skip to main content
15,898,134 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cross Post. Pin
J4amieC19-Nov-08 3:00
J4amieC19-Nov-08 3:00 
GeneralRe: Cross Post. Pin
Simon P Stevens19-Nov-08 3:03
Simon P Stevens19-Nov-08 3:03 
GeneralRe: Cross Post. Pin
DotNetCoderJunior19-Nov-08 3:10
DotNetCoderJunior19-Nov-08 3:10 
GeneralRe: Cross Post. Pin
DotNetCoderJunior19-Nov-08 3:12
DotNetCoderJunior19-Nov-08 3:12 
GeneralRe: Cross Post. Pin
Simon P Stevens19-Nov-08 3:31
Simon P Stevens19-Nov-08 3:31 
GeneralRe: Cross Post. Pin
Paul Conrad19-Nov-08 5:04
professionalPaul Conrad19-Nov-08 5:04 
QuestionSetting Role Based Permission for User Pin
Piratenwichtl200019-Nov-08 1:09
Piratenwichtl200019-Nov-08 1:09 
AnswerRe: Setting Role Based Permission for User Pin
#realJSOP19-Nov-08 1:21
professional#realJSOP19-Nov-08 1:21 
You shouldn't store data in the application's folder. You should do that in the "special folder" where special permissions shouldn't be required. Here's some code that works on XP and Vista (apologies if it requires scrolling on your screen):

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace MyLib
{
	public class Utility
	{

//--------------------------------------------------------------------------------
/// <summary>
/// Create (if necessary) the specified application data folder. This method 
/// only creates the root folder, and will throw an exception if more than one 
/// folder is specified.  For instance, "\MyApp" is valid, but 
/// "\MyApp\MySubFolder" is not.
/// </summary>
/// <param name="folderName">A single folder name (can have a backslash at either or 
/// both ends).</param>
/// <returns>The fully qualified path that was created (or that already exists)</returns>
public static string CreateAppDataFolder(string folderName)
{
	string appDataPath = "";
	string dataFilePath = "";

	folderName = folderName.Trim();
	if (folderName != "")
	{
		try
		{
			// set the directory where the file will come from 
			// under XP, the folder name is "C:\Documents and Settings\All Users\Application Data\[folderName]"
			// under Vista, the folder name is "C:\Program Data\[folderName]"
			appDataPath = System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
		}
		catch (Exception ex)
		{
			throw ex;
		}
		if (folderName.Contains("\\"))
		{
			string[] path = folderName.Split('\\');
			int folderCount = 0;
			int folderIndex = -1;
			for (int i = 0; i < path.Length; i++)
			{
				string folder = path[i];
				if (folder != "")
				{
					if (folderIndex == -1)
					{
						folderIndex = i;
					}
					folderCount++;
				}
			}
			if (folderCount != 1)
			{
				throw new Exception("Invalid folder name specified (this function only creates the root app data folder for the application).");
			}
			folderName = path[folderIndex];
		}
	}
	if (folderName == "")
	{
		throw new Exception("Processed folder name resulted in an empty string.");
	}
	try
	{
		dataFilePath = System.IO.Path.Combine(appDataPath, folderName);
		if (!Directory.Exists(dataFilePath))
		{
			Directory.CreateDirectory(dataFilePath);
		}
	}
	catch (Exception ex)
	{
		throw ex;
	}
	return dataFilePath;
}
}
}
// Usage:
//
using MyLib;
string dataFolder = Utility.CreateAppDataFolder("MyAppFolder");



"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


GeneralRe: Setting Role Based Permission for User Pin
J a a n s19-Nov-08 3:19
professionalJ a a n s19-Nov-08 3:19 
GeneralRe: Setting Role Based Permission for User Pin
Piratenwichtl200019-Nov-08 6:31
Piratenwichtl200019-Nov-08 6:31 
AnswerRe: Setting Role Based Permission for User Pin
Not Active19-Nov-08 1:28
mentorNot Active19-Nov-08 1:28 
QuestionImage display Pin
B8719-Nov-08 0:20
B8719-Nov-08 0:20 
AnswerRe: Image display Pin
Simon P Stevens19-Nov-08 0:37
Simon P Stevens19-Nov-08 0:37 
AnswerRe: Image display Pin
Giorgi Dalakishvili19-Nov-08 0:37
mentorGiorgi Dalakishvili19-Nov-08 0:37 
QuestionPicture box Pin
B8718-Nov-08 23:50
B8718-Nov-08 23:50 
AnswerRe: Picture box Pin
Guffa18-Nov-08 23:58
Guffa18-Nov-08 23:58 
GeneralRe: Picture box Pin
B8719-Nov-08 0:05
B8719-Nov-08 0:05 
GeneralRe: Picture box Pin
Guffa19-Nov-08 1:08
Guffa19-Nov-08 1:08 
GeneralRe: Picture box Pin
J4amieC19-Nov-08 1:27
J4amieC19-Nov-08 1:27 
GeneralRe: Picture box Pin
V.19-Nov-08 2:39
professionalV.19-Nov-08 2:39 
GeneralRe: Picture box Pin
J4amieC19-Nov-08 2:59
J4amieC19-Nov-08 2:59 
Questiondesign problem with static classes Pin
NikoTanghe18-Nov-08 23:26
NikoTanghe18-Nov-08 23:26 
AnswerRe: design problem with static classes Pin
Simon P Stevens19-Nov-08 0:44
Simon P Stevens19-Nov-08 0:44 
QuestionConnection To DataBase Pin
Thaer Hamael18-Nov-08 23:13
Thaer Hamael18-Nov-08 23:13 
AnswerRe: Connection To DataBase Pin
Pedram Behroozi18-Nov-08 23:17
Pedram Behroozi18-Nov-08 23:17 

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.