Hunt

Saturday, January 23, 2010

FOLDER CREATION PRGRAMMATICALLY USING C#

URL
====================
http://www.sarampalis.org/articles/dotnet/dotnet0002.shtml

http://search.code-head.com/F-Share-folder-files-and-setting-permission-on-C-over-the-internet-1404158


--http://www.codeproject.com/KB/system/Share-Folder-c_.aspx

http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/
====================

/*using System;
using System.IO;
using System.Net;
using System.Management;*/

try
{
// create a directory
Directory.CreateDirectory(@"C:\MyTestShare");
// Create a ManagementClass object
ManagementClass managementClass = new ManagementClass("Win32_Share");
// Create ManagementBaseObjects for in and out parameters
ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
ManagementBaseObject outParams;
// Set the input parameters
inParams["Description"] = "My Files Share";
inParams["Name"] = "My Files Share";
inParams["Path"] = @"C:\MyTestShare";
inParams["Type"] = 0x0; // Disk Drive
// Invoke the method on the ManagementClass object
outParams = managementClass.InvokeMethod("Create", inParams, null);
// Check to see if the method invocation was successful
if((uint)(outParams.Properties["ReturnValue"].Value) != 0)
{
throw new Exception("Unable to share directory.");
}
}
catch(Exception e)
{
return e.Message;
}

=============================================================

TO CREATE A FOLDER ONLY
===============================================================
System.IO.Directory.CreateDirectory(@"F:\MyFirstDir");
==============================================================

No comments:

Post a Comment