Click here to Skip to main content
15,921,371 members
Home / Discussions / C#
   

C#

 
Questiondbf database files import net2.0 Pin
hpetriffer6-Apr-06 4:44
hpetriffer6-Apr-06 4:44 
QuestionDataGrid in .net 1.1 and 2.0 ??? Pin
amin_behzadi6-Apr-06 4:41
professionalamin_behzadi6-Apr-06 4:41 
AnswerRe: DataGrid in .net 1.1 and 2.0 ??? Pin
NeelV7-Apr-06 2:49
NeelV7-Apr-06 2:49 
QuestionMoving files programatically Pin
naglbitur6-Apr-06 4:14
naglbitur6-Apr-06 4:14 
AnswerRe: Moving files programatically Pin
Judah Gabriel Himango6-Apr-06 4:28
sponsorJudah Gabriel Himango6-Apr-06 4:28 
GeneralRe: Moving files programatically Pin
naglbitur6-Apr-06 5:09
naglbitur6-Apr-06 5:09 
GeneralRe: Moving files programatically Pin
Judah Gabriel Himango6-Apr-06 5:16
sponsorJudah Gabriel Himango6-Apr-06 5:16 
QuestionDirectory listing Pin
wistiti56-Apr-06 3:51
wistiti56-Apr-06 3:51 
Hello,

I'm building an upload tool in c# but I only want to show de directories where the user has access to from the computer he is sitting on.

I made a script that lists al the directories in a treeview, but it gives an error when it comes to a directory where the user had no access to.
(ex. c:/documents and setting/administrator)

Here a sample of my script

private void FillDirectoryTree(TreeView tvw)
{
tvw.Nodes.Clear();

string[] strDrives = Environment.GetLogicalDrives();

foreach (string rootDirName in strDrives)
{
MessageBox.Show(rootDirName);

if(rootDirName == "C:\\")
{
try
{
DirectoryInfo dir = new DirectoryInfo(rootDirName);
dir.GetDirectories();

TreeNode ndRoot = new TreeNode(rootDirName);

tvw.Nodes.Add(ndRoot);

GetSubDirectoryNodes(ndRoot, ndRoot.Text, 1);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}

Application.DoEvents();
}

private void GetSubDirectoryNodes(TreeNode parentNode, string fullName, int level)
{
DirectoryInfo dir = new DirectoryInfo(fullName);
DirectoryInfo[] dirSubs = dir.GetDirectories();

foreach (DirectoryInfo dirSub in dirSubs)
{
if ((dirSub.Attributes & FileAttributes.Hidden) != 0)
{
continue;
}

TreeNode subNode = new TreeNode(dirSub.Name);

parentNode.Nodes.Add(subNode);

if (level < MaxLevel)
{
GetSubDirectoryNodes(subNode, dirSub.FullName, level + 1);
}
}
}

private void tvDestFiles_AfterSelect(object sender, TreeViewEventArgs e)
{
txtTargetDir.Text = tvDestFiles.SelectedNode.FullPath;
}

private void btnUploadFiles_Click(object sender, EventArgs e)
{
List<fileinfo> fileList = GetFileList();

foreach (FileInfo file in fileList)
{
try
{
file.CopyTo(txtTargetDir.Text + "\\" + file.Name, true);

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Application.DoEvents();
}

private List<fileinfo> GetFileList()
{
List<string> fileNames = new List<string>();

foreach (TreeNode theNode in tvSourceFiles.Nodes)
{
GetCheckedFiles(theNode, fileNames);
}

List<fileinfo> fileList = new List<fileinfo>();

foreach (string fileName in fileNames)
{
FileInfo file = new FileInfo(fileName);

if (file.Exists)
{
fileList.Add(file);
}
}

return fileList;
}

private void GetCheckedFiles(TreeNode node, List<string> fileNames)
{
if (node.Nodes.Count == 0)
{
if (node.Checked)
{
string fullPath = GetParentString(node);
fileNames.Add(fullPath);
}
}
else
{
foreach (TreeNode n in node.Nodes)
{
GetCheckedFiles(n, fileNames);
}
}
}

private string GetParentString(TreeNode node)
{
if (node.Parent == null)
{
return node.Text;
}
else
{
return GetParentString(node.Parent) + node.Text + (node.Nodes.Count == 0 ? "" : "\\");
}
}


Some help please

Thx

wistiti 5
AnswerRe: Directory listing Pin
Judah Gabriel Himango6-Apr-06 4:37
sponsorJudah Gabriel Himango6-Apr-06 4:37 
QuestionTreeView dilema. Please Help! Pin
zaboboa6-Apr-06 3:43
zaboboa6-Apr-06 3:43 
AnswerRe: TreeView dilema. Please Help! Pin
Judah Gabriel Himango6-Apr-06 4:46
sponsorJudah Gabriel Himango6-Apr-06 4:46 
GeneralRe: TreeView dilema. Please Help! Pin
zaboboa6-Apr-06 5:22
zaboboa6-Apr-06 5:22 
GeneralRe: TreeView dilema. Please Help! Pin
Judah Gabriel Himango6-Apr-06 5:32
sponsorJudah Gabriel Himango6-Apr-06 5:32 
QuestionProgramming windows form in .NET Pin
bluehai6-Apr-06 3:26
bluehai6-Apr-06 3:26 
AnswerRe: Programming windows form in .NET Pin
scoroop6-Apr-06 3:43
scoroop6-Apr-06 3:43 
AnswerRe: Programming windows form in .NET Pin
spif20016-Apr-06 4:17
spif20016-Apr-06 4:17 
GeneralRe: Programming windows form in .NET Pin
bluehai6-Apr-06 4:50
bluehai6-Apr-06 4:50 
GeneralRe: Programming windows form in .NET Pin
Judah Gabriel Himango6-Apr-06 5:01
sponsorJudah Gabriel Himango6-Apr-06 5:01 
GeneralRe: Programming windows form in .NET Pin
bluehai6-Apr-06 5:06
bluehai6-Apr-06 5:06 
GeneralRe: Programming windows form in .NET Pin
Judah Gabriel Himango6-Apr-06 5:09
sponsorJudah Gabriel Himango6-Apr-06 5:09 
QuestionUsing win32 LIB in C# Pin
t4ure4n6-Apr-06 3:03
t4ure4n6-Apr-06 3:03 
AnswerRe: Using win32 LIB in C# Pin
Andy Moore6-Apr-06 3:09
Andy Moore6-Apr-06 3:09 
QuestionRe: Using win32 LIB in C# Pin
t4ure4n7-Apr-06 0:19
t4ure4n7-Apr-06 0:19 
AnswerRe: Using win32 LIB in C# Pin
Andy Moore7-Apr-06 3:15
Andy Moore7-Apr-06 3:15 
Question[Message Deleted] Pin
t4ure4n6-Apr-06 2:42
t4ure4n6-Apr-06 2:42 

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.