Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void UploadStoryboardButton_Click(object sender, RoutedEventArgs e)
- {
- Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
- // Set filter for file extension and default file extension
- dlg.DefaultExt = ".ksb";
- dlg.Filter = "Konsolidovaný storyboard (.ksb)|*.ksb";
- // Display OpenFileDialog by calling ShowDialog method
- Nullable<bool> result = dlg.ShowDialog();
- // Get the selected file name and display in a TextBox
- if (result == true)
- {
- //create a folder
- try
- {
- //parse and create distribution folder
- FileInfo fi = new FileInfo(dlg.FileName);
- string sbname = fi.Name.Split('.')[0] + @"\";
- string tempdir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
- string sharedir = tempdir + @"\" + sbname;
- bool IsExists = System.IO.Directory.Exists(sharedir);
- if (!IsExists)
- {
- DirectoryInfo sharedirDI = new DirectoryInfo(sharedir);
- DirectorySecurity sharedirSC = new DirectorySecurity();
- sharedirSC.SetAccessRuleProtection(true, false);
- sharedirSC.AddAccessRule(new FileSystemAccessRule(@"Everyone", FileSystemRights.FullControl, AccessControlType.Allow));
- sharedirSC.AddAccessRule(new FileSystemAccessRule(@"Administrators", FileSystemRights.FullControl, AccessControlType.Allow));
- System.IO.Directory.CreateDirectory(sharedir, sharedirSC);
- File.Copy(dlg.FileName, sharedir + fi.Name, true);
- }
- else
- {
- File.Copy(dlg.FileName, sharedir + fi.Name, true);
- }
- //create a share
- try
- {
- // 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"] = "Disttemp";
- inParams["Name"] = sbname;
- inParams["Path"] = sharedir;
- inParams["MaximumAllowed"] = null;
- inParams["Password"] = null;
- inParams["Access"] = null;
- inParams["Type"] = 0x000000;
- //Another Type:
- // DISK_DRIVE = 0x0
- // PRINT_QUEUE = 0x1
- // DEVICE = 0x2
- // IPC = 0x3
- // DISK_DRIVE_ADMIN = 0x80000000
- // PRINT_QUEUE_ADMIN = 0x80000001
- // DEVICE_ADMIN = 0x80000002
- // IPC_ADMIN = 0x8000003
- //inParams["MaximumAllowed"] = int maxConnectionsNum;
- // 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.");
- }
- else
- {
- //vytvoříme z dat příkaz pro přehrávač, který se UDPčkem odešle
- NetWorker1.uploadNewStoryboard(ipblock.Text, fi.Name);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "error!");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement