matt's profileSharepoint Development f...PhotosBlogListsMore Tools Help

Sharepoint Development for Beginners

Sharepoint stuff I do at work and other stuff
March 04

Creating a basic custom field that looks up SQL data

protected override void CreateChildControls()
       {
           base.CreateChildControls();

           conn = new SqlConnection("Server=(local);Initial Catalog=Lee;User Id=sa;Password=1!Qwerty;");
           dsCustomers = new DataSet();

           daCustomers = new SqlDataAdapter("select TerrID, Territory from ListOfTerritories", conn);
           daCustomers.Fill(dsCustomers, "ListOfTerritories");

           this.table = new HtmlTable();

           HtmlTableRow row = new HtmlTableRow();
           table.Rows.Add(row);

           HtmlTableCell cell = null;

           if (this.ControlMode == SPControlMode.Edit ||
               this.ControlMode == SPControlMode.New)
           {
               cell = new HtmlTableCell();
               cell.ColSpan = 1;
               cell.Attributes["class"] = "ms-formdescription";
               cell.InnerText = "Choose a Region:";

               row.Cells.Add(cell);

               row = new HtmlTableRow();
               cell = new HtmlTableCell();
               this.listBox = new ListBox();
               this.listBox.Rows = 12;
               this.listBox.DataSource = dsCustomers;
               this.listBox.DataTextField = "Territory";
               this.listBox.DataValueField = "Territory";
               this.listBox.DataBind();

               cell.Controls.Add(this.listBox);
               row.Cells.Add(cell);
               table.Rows.Add(row);
           }

           base.Controls.Add(table);
       }

       public override void UpdateFieldValueInItem()
       {
           this.EnsureChildControls();

           try
           {
               this.Value = this.listBox.SelectedValue;
               this.ItemFieldValue = this.Value;
           }
           catch
           {
               ;
           }
       }

       protected override void Render(HtmlTextWriter output)
       {
           this.table.RenderControl(output);
       }

February 25

Creating a custom field that checks another column’s value against it

public override string GetValidatedString(object value)
       {
           SPList spl = SPContext.Current.List;
           string strValue = value.ToString();

           if (value.ToString().Trim() != "")
           {
               SPQuery q = new SPQuery();
               q.Query = "<Where><Eq><FieldRef Name='ProposalNumber'/>" +
                         "<Value Type='Text'>" + strValue + "</Value></Eq></Where>";
               SPListItemCollection lic = spl.GetItems(q);

               if (lic.Count != 0)
               {
                   throw new SPFieldValidationException("Proposal Number already exists");
               }
           }

           return value.ToString();
       }

February 24

Creating a new Site Collection

After a few weeks of Sharepoint programming I realized I had secuirty errors as I used the site under other accounts.

One example is creating a Site Collection.

 
 
SPSecurity.RunWithElevatedPrivileges
                                       (delegate()
                                       {                                       
                                           if (properties.WebUrl == "http://mhlaptop")
                                           {
                                               webApplication.Sites.Add("/sites/" + strTitleValue,
                                                   strProjectTitleValue,
                                                   "The proposal number is" + strTitleValue,
                                                   1033,
                                                   "Lee_Opp_Site2",
                                                   @"NORTHAMERICA\mherb",
                                                   "Administrator",
                                                   "anon@anon.com");
                                           }
                                           else if (properties.WebUrl == "http://punkouter-pc")
                                           {
                                               webApplication.Sites.Add("/sites/" + strTitleValue,
                                               strProjectTitleValue,
                                               "The proposal number is" + strTitleValue,
                                               1033,
                                               "Lee_Opp_Site2",
                                               @"punkouter",
                                               "Administrator",
                                               "anon@anon.com");
                                           }
February 23

Working with Syncfusion DOCIO and sharepoint today

 
 for (int i = 0; i < equipmentList.Count; i++)
            {
                for (int j = 0; j <= 2; j++)
                {
                    iwp = iwt[i + 1, j].AddParagraph() as WParagraph;
                    iwp.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                  
                    if (j == 0)
                    {
                        iwtr = iwp.AppendText(equipmentList[i].strEquipment);
                    }

                    if (j == 1)
                    {
                        iwtr = iwp.AppendText(equipmentList[i].strCoverage);
                    }

                    if (j == 2)
                    {
                        iwtr = iwp.AppendText(equipmentList[i].strSchedule);
                    }                 
                }
            }
 

Video

 
Video: red car  
Video: FISHOCK  
Video: Fog Machine by BAD WEDDING  
Video: BBT