public static void SiteInvoke(SiteAction action) { string site = getSiteIdByName("AubeWeb"); if (site == null) { return; } try { ConnectionOptions connectionOptions = new ConnectionOptions() { Impersonation = ImpersonationLevel.Impersonate }; ManagementScope managementScope = new ManagementScope(@"\\" + "localhost" + @"\root\microsoftiisv2", connectionOptions); managementScope.Connect(); if (managementScope.IsConnected == false) { MsgBox.Show("Could not connect to WMI namespace " + managementScope.Path, "Connect Failed"); } else { SelectQuery selectQuery = new SelectQuery(string.Format("Select * From IIsWebServer Where Name = 'W3SVC/{0}'", site)); using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(managementScope, selectQuery)) { foreach (ManagementObject objMgmt in managementObjectSearcher.Get()) { objMgmt.InvokeMethod(action.ToString(), new object[0]); } } } } catch (Exception ex) { if (ex.ToString().Contains("Invalid namespace")) { MsgBox.Show("Invalid Namespace Exception" + Environment.NewLine + Environment.NewLine + "This program only works with IIS 6 and later", string.Format("Can't {0} website", action)); } else { MsgBox.Show(ex.Message, string.Format("Can't {0} website", action)); } } }
public Form(string provider, SiteAction action, string frame, string name, string id, string url, string method) { Provider = provider; Frame = frame; Controls = new List <Control>(); Name = name; Id = id; ControlType = ControlType.Form; FormatType = FormatType.Widget; Method = method; Action = action; Url = url; }
private void ProcessFolder(Folder _xfolder, List _list, List _dList) { LogVerbose("{0}--{1}", _xfolder.Name, _xfolder.ServerRelativeUrl); try { Folder _pFolder = _xfolder.ParentFolder; this.ClientContext.Load(_pFolder); this.ClientContext.ExecuteQuery(); if (SiteAction.Equals("create-folders", StringComparison.CurrentCultureIgnoreCase)) { //Create folder in target library CreateFolderInDocLib(_list, _dList, _xfolder, _pFolder); } if (SiteAction.Equals("copy-files", StringComparison.CurrentCultureIgnoreCase)) { //Process items for attachement GetItemsWithinFolder(_list, _dList, _xfolder); } //Process subfolders FolderCollection _folders = _xfolder.Folders; this.ClientContext.Load(_folders); this.ClientContext.ExecuteQuery(); foreach (Folder _folder in _folders) { ProcessFolder(_folder, _list, _dList); } } catch (Exception e) { LogError(e, ">>>>>> processFolder - {0}", e.Message); } }
public void UpdateSite( string siteName, SiteAction action ) { }
/// <summary> /// Process the request /// </summary> public override void ExecuteCmdlet() { base.ExecuteCmdlet(); LogVerbose("Now migrating attachments from list to library {0}.", this.DestinationLibraryName); var result = System.IO.Path.GetTempPath(); var resultdir = new System.IO.DirectoryInfo(result); _resultLogDirectory = resultdir.CreateSubdirectory("downloadedAttachments", resultdir.GetAccessControl()); List _srclist = this.ClientContext.Web.Lists.GetByTitle(SourceListName); Folder _rootFolder = _srclist.RootFolder; this.ClientContext.Load(_srclist); this.ClientContext.Load(_rootFolder); this.ClientContext.ExecuteQuery(); List _dlist = this.ClientContext.Web.Lists.GetByTitle(DestinationLibraryName); Folder _drootFolder = _dlist.RootFolder; this.ClientContext.Load(_dlist); this.ClientContext.Load(_drootFolder); this.ClientContext.ExecuteQuery(); LogVerbose("Source List {0} with root folder {1}", _srclist.Title, _rootFolder.ServerRelativeUrl); LogVerbose("Destination List {0} with root folder {1}", _dlist.Title, _drootFolder.ServerRelativeUrl); //check if list is discussion list bool _isDiscussionList = false; ContentTypeCollection contentTypeColl = _srclist.ContentTypes; this.ClientContext.Load(contentTypeColl); this.ClientContext.ExecuteQuery(); LogVerbose("Checking Content types:"); foreach (ContentType contentType in contentTypeColl) { if (contentType.Name.IndexOf("Discussion") > -1) { LogVerbose("Name: {0} Id: {1}", contentType.Name, contentType.Id); _isDiscussionList = true; break; } } if (!(String.IsNullOrEmpty(StartingFolder))) { //Create StartingFolder _dlist.RootFolder.Folders.Add(StartingFolder); _dlist.Update(); this.ClientContext.ExecuteQuery(); } if (SiteAction.Equals("copy-files", StringComparison.CurrentCultureIgnoreCase)) { //Process items for attachement GetItemsWithinFolder(_srclist, _dlist, _srclist.RootFolder); } if (!_isDiscussionList) { FolderCollection _folders = _rootFolder.Folders; this.ClientContext.Load(_folders); this.ClientContext.ExecuteQuery(); foreach (Folder _folder in _folders) { LogVerbose(">>>> {0}", _folder.Name); if ((_folder.Name != "Attachments") && (_folder.Name != "Item")) { LogVerbose(">>>>" + _folder.Name); ProcessFolder(_folder, _srclist, _dlist); } } } }