ĐÀO TẠO DOANH NGHIỆP : SỞ KHOA HỌC CÔNG NGHỆ TỈNH ĐỒNG NAI

ENTERPRISE TRAINING: DONG NAI DEPARTMENT OF SCIENCE AND TECHNOLOGY.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

HÌNH ẢNH TẬP HUẤN LỚP SHAREPOINT WORKFLOW VÀ KIẾN TRÚC SHAREPOINT

PHOTOS OF SHAREPOINT WORKFLOW AND ARCHITECTURE CLASS.

Monday, March 5, 2012

Part 1: Develop on sanbox solution and resolve error


Step 1: Open Visual Studio 2010 | Add New Project | Sharepoint | Empty Sharepoint Project and named is DevSanbox
Step 2: Choose your Web App and choose deploy sanbox
Step 3: Add new item | Web Part and named is DevSanbox
Step 4: code in event  CreateChildControls as
Code here
protected override void CreateChildControls()
        {
            Literal literalResult = new Literal();
            this.Controls.Add(literalResult);

            SPSite spSite = SPControl.GetContextSite(Context);
            SPWeb spWeb = spSite.OpenWeb();           
            SPList spList = spWeb.Lists["Tasks"];
            SPQuery spQuery=new SPQuery();
            SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
            foreach (SPListItem item in spListItemCollection)
            {
                literalResult.Text += item["Title"] + "||";
            }
        }
Step 5: Build project and Package it
Step 6: Open your web application =>  back to top level site, Click Site Actions | Site Setting | Click “Solutions” link | Upload Solution
Step 7: Choose  your .WSP in bin folder and Active it
Step 8: Result as
Step 9: Add Web Part as
Step 10: Error appear
Step 11: Solve problem. Replace code as
protected override void CreateChildControls()
        {
            Literal literalResult = new Literal();
            this.Controls.Add(literalResult);

            //SPSite spSite = SPControl.GetContextSite(Context);
            //SPWeb spWeb = spSite.OpenWeb();           
            using (SPWeb spWeb = SPContext.Current.Web)//Important
            {
                SPList spList = spWeb.Lists["Tasks"];
                SPQuery spQuery = new SPQuery();
                SPListItemCollection spListItemCollection = spList.GetItems(spQuery);
                foreach (SPListItem item in spListItemCollection)
                {
                    literalResult.Text += item["Title"] + "||";
                }
            }
           
        }
Step  12: Deactive Solution
Step 13: Upload solution again and Active It
Step 14: Result as

Part 1: Attach file to Web Part using module feature


Step 1: Open visual studio 2010 | New | Project | Empty Sharepoint Project , project name is: ApplyCssUseModuleFeartureSanbox
Step 2: Choose deploy sanbox solution
Step 3: Add new Item
Step 4: Choose Module, name is CallFileCssOrScript
Step 5: View UI below
Step 6: Rename Sample.txt file to Sample.css
Step 7: Copy  code  Url="_catalogs/masterpage" RootWebOnly="TRUE" List="116" and paste to here
Step 8: Delete Url  CallFileCssOrScript\ 
Step 9: Copy  Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE" and paste to here
Step 10: Open file Sample.css and delete content
Step 11: Paste code below to content of file Sample.css
.tableRow
{
    background-color:Orange;
    color:Red;
}
Step 12: Add new Item | Web Part | name is ApplyCssUseModuleFeartureSanbox
Step 13: Write code  CreateChildControls
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace ApplyCssUseModuleFeartureSanbox.ApplyCssUseModuleFeartureSanbox
{
    [ToolboxItemAttribute(false)]
    public class ApplyCssUseModuleFeartureSanbox : WebPart
    {
        protected override void CreateChildControls()
        {
            //Create new table object
            Table table = new Table();
            table.GridLines = GridLines.Both;
            //The first row
            TableRow tableRow = new TableRow();
            tableRow.CssClass = "tableRow";//Call css from module
            TableCell tableCell = new TableCell();
            tableCell.Text = "Your name";
            tableRow.Cells.Add(tableCell);
            tableCell = new TableCell();
            tableCell.Text = "Email";
            tableRow.Cells.Add(tableCell);
            tableCell = new TableCell();
            tableCell.Text = "Phone number";
            tableRow.Cells.Add(tableCell);
            table.Rows.Add(tableRow);
            //The second row
            tableRow = new TableRow();
            tableCell = new TableCell();
            tableCell.Text = "Do Quoc Hung";
            tableRow.Cells.Add(tableCell);
            tableCell = new TableCell();
            tableCell.Text = "quochung211187@gmail.com";
            tableRow.Cells.Add(tableCell);
            tableCell = new TableCell();
            tableCell.Text = "0909263861";
            tableRow.Cells.Add(tableCell);
            table.Rows.Add(tableRow);
            this.Controls.Add(table);
        }
    }
}
Step 14: before build, you test file: don’t appear file in Folder Debug ?
Step 15: Build Project
Step 16: After Build, you see appear 2 file below
Step 17: Then Package Project
Step 18: Appear Error because path with length more 248 character (if error)
Step 19: Right click project | Properties | Edit Assembly name and Default namespace
Step 20: Edit to ApplyCss for Assembly name and Default namespace
Step 21: Rebuild project
Step 22: Delete two old file below (if true)
Step 23: Package project
Step 24: Result, file .wsp created
Step 25: Open Site | Site Action | Site Setting 
Step 26: Click Solution link
Step 27: Click Icon Upload Solution
Step 28: Choose file .wsp in your  folder bin\debug
Step 29: Click Ok | click Icon Active
Step 30: Add Web Part – Click Site Action | Edit Page
Step 31: Click Tab Insert | choose Web Part
Step 32: in Categories Web Part | Choose Category  Custom | Choose your file .WSP and click Add
Step 33: Click tab Page | Click Icon Stop Editing
Step 34: Result below but css don’t Apply

Step 35: you can test file Sample.css when you register in Element.xml of Module below and result you see file is exist
Step 36: Reason css don’t apply because css do not register, you paste code below to your Web Part
      //Register to file css
      Literal literalCss = new Literal();
      this.Controls.Add(literalCss);
      literalCss.Text = "<link rel='stylesheet' type='text/css' href='/_catalogs/masterpage/Sample.css'/>";
Step 37: Rebuild project and build project and package project again, then Deactive WSP | choose you .wsp file and click icon Deactive
Step 38: Poupup appear, you click Deactive Icon
Step 39: Result below, Css is apply to table…