Advertisement
thebys

DSDNM - sharecreater

Mar 3rd, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.47 KB | None | 0 0
  1.         private void UploadStoryboardButton_Click(object sender, RoutedEventArgs e)
  2.         {
  3.             Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
  4.             // Set filter for file extension and default file extension
  5.             dlg.DefaultExt = ".ksb";
  6.             dlg.Filter = "Konsolidovaný storyboard (.ksb)|*.ksb";
  7.             // Display OpenFileDialog by calling ShowDialog method
  8.             Nullable<bool> result = dlg.ShowDialog();
  9.             // Get the selected file name and display in a TextBox
  10.  
  11.             if (result == true)
  12.             {
  13.                 //create a folder
  14.                 try
  15.                 {
  16.                     //parse and create distribution folder
  17.                     FileInfo fi = new FileInfo(dlg.FileName);
  18.                     string sbname = fi.Name.Split('.')[0] + @"\";
  19.                     string tempdir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
  20.                     string sharedir = tempdir + @"\" + sbname;
  21.                     bool IsExists = System.IO.Directory.Exists(sharedir);
  22.                     if (!IsExists)
  23.                     {
  24.                         DirectoryInfo sharedirDI = new DirectoryInfo(sharedir);
  25.                         DirectorySecurity sharedirSC = new DirectorySecurity();
  26.                         sharedirSC.SetAccessRuleProtection(true, false);
  27.                         sharedirSC.AddAccessRule(new FileSystemAccessRule(@"Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
  28.                         sharedirSC.AddAccessRule(new FileSystemAccessRule(@"Administrators", FileSystemRights.FullControl, AccessControlType.Allow));
  29.                         System.IO.Directory.CreateDirectory(sharedir, sharedirSC);
  30.  
  31.                         File.Copy(dlg.FileName, sharedir + fi.Name, true);
  32.                     }
  33.                     else
  34.                     {
  35.                         File.Copy(dlg.FileName, sharedir + fi.Name, true);
  36.                     }
  37.  
  38.  
  39.  
  40.                     //create a share
  41.                     try
  42.                     {
  43.                         // Create a ManagementClass object
  44.                         ManagementClass managementClass = new ManagementClass("Win32_Share");
  45.                         // Create ManagementBaseObjects for in and out parameters
  46.                         ManagementBaseObject inParams = managementClass.GetMethodParameters("Create");
  47.                         ManagementBaseObject outParams;
  48.                         // Set the input parameters
  49.                         inParams["Description"] = "Disttemp";
  50.                         inParams["Name"] = sbname;
  51.                         inParams["Path"] = sharedir;
  52.                         inParams["MaximumAllowed"] = null;
  53.                         inParams["Password"] = null;
  54.                         inParams["Access"] = null;
  55.                         inParams["Type"] = 0x000000;
  56.                         //Another Type:
  57.                         // DISK_DRIVE = 0x0
  58.                         // PRINT_QUEUE = 0x1
  59.                         // DEVICE = 0x2
  60.                         // IPC = 0x3
  61.                         // DISK_DRIVE_ADMIN = 0x80000000
  62.                         // PRINT_QUEUE_ADMIN = 0x80000001
  63.                         // DEVICE_ADMIN = 0x80000002
  64.                         // IPC_ADMIN = 0x8000003
  65.                         //inParams["MaximumAllowed"] = int maxConnectionsNum;
  66.                         // Invoke the method on the ManagementClass object
  67.                         outParams = managementClass.InvokeMethod("Create", inParams, null);
  68.                         // Check to see if the method invocation was successful
  69.                         if ((uint)(outParams.Properties["ReturnValue"].Value) != 0)
  70.                         {
  71.                             throw new Exception("Unable to share directory.");
  72.                         }
  73.                         else
  74.                         {
  75.                             //vytvoříme z dat příkaz pro přehrávač, který se UDPčkem odešle
  76.                             NetWorker1.uploadNewStoryboard(ipblock.Text, fi.Name);
  77.                         }
  78.                     }
  79.                     catch (Exception ex)
  80.                     {
  81.                         MessageBox.Show(ex.Message, "error!");
  82.                     }
  83.  
  84.                 }
  85.                 catch (Exception ex)
  86.                 {
  87.                     MessageBox.Show(ex.Message);
  88.                 }
  89.             }
  90.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement