/// <summary> /// This static method is used to get the values of document library name and description /// that are entered by the user. /// </summary> /// <returns>ArrayList of values</returns> public static ArrayList GetDocListValues() { ArrayList docValues = new ArrayList(); NewDocLibrary newDocLibrary = new NewDocLibrary(); newDocLibrary.ShowDialog(); docValues.Add(newDocLibrary.tbxDocLibraryName.Text.Trim()); docValues.Add(newDocLibrary.tbxDocLibraryDesc.Text.Trim()); return(docValues); }
private void btnFormLibraryNew_Click(object sender, EventArgs e) { if (tbxUserName.Text.Trim() == "" || tbxPassword.Text.Trim() == "" || tbxDomain.Text.Trim() == "") { MessageBox.Show("You should provide the Credentials before creating SharePoint Library", "Create SharePoint Library"); return; } if (drpdnlFormLibrary.Text.Trim() != "") { drpdnlFormLibrary.Text = ""; } ArrayList docLibValues = new ArrayList(); SPSite site = null; try { drpdnlFormLibrary.SelectedText = ""; docLibValues = NewDocLibrary.GetDocListValues(); WindowsImpersonationContext wic = Utility.CreateIdentity(tbxUserName.Text.Trim(), tbxDomain.Text.Trim(), tbxPassword.Text.Trim()).Impersonate(); //check whether user has entered full url including "http" if (tbxSharePointURL.Text.StartsWith("http")) { site = new SPSite(tbxSharePointURL.Text.Trim()); } else { site = new SPSite("http://" + tbxSharePointURL.Text.Trim()); } SPWeb web = site.OpenWeb(); SPListTemplate docLibrary = web.ListTemplates["Document Library"]; drpdnlFormLibrary.Items.Add(docLibValues[0].ToString()); drpdnlFormLibrary.SelectedText = docLibValues[0].ToString(); tbxDocLibDesc.Text = docLibValues[1].ToString(); web.Lists.Add(drpdnlFormLibrary.Text.Trim(), docLibValues[1].ToString(), docLibrary); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error"); } }