在SharePoint中对文档库(列表)进行的一些操作

以下是我在开发SharePoint过程中写的对文档库和列表进行的一些基本操作,先写下来,日后在加。 using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

using  System.Data.SqlClient;
using  System.IO;
using  Microsoft.SharePoint;
using  yesinda.yesindakms.sharepoint;
using  yesinda.yesindakms.sharepoint.List;
using  Microsoft.SharePoint.WebControls;
using  Microsoft.SharePoint.Utilities;

public  partial  class  usercontrol_CreateNewDoc : System.Web.UI.UserControl
{
    定义变量和属性
定义变量和属性

    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            
//绑定DropDownList控件
            BindControl();
            
//绑定TreeView控件
            TreeViewBind(this.TreeView1);
            TreeViewBind(
this.TreeView2);
            
//AddUserTreeNode(this.TreeView3);
            
//绑定GridView数据控件
            BindGrid();

            HostName 
= Request.UserHostName;
        }

    }


    为TreeView添加节点
为TreeView添加节点

    绑定TreeView控件
绑定TreeView控件

    创建数据源
创建数据源

    绑定控件
绑定控件

    发送文档
发送文档

    权限控制
权限控制

    上传文档
上传文档

    创建文件夹
创建文件夹

    
/**//// <summary>
    
/// 执行文档上传
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void Button1_Click(object sender, EventArgs e)
    
{
        
if (this.FileUpload1.FileName != "")
        
{
            UpLoadDocument();
        }

    }


    
/**//// <summary>
    
/// 选择文档库的路径
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ddlDocTitle2_SelectedIndexChanged(object sender, EventArgs e)
    
{
        Url 
= this.ddlDocTitle2.SelectedValue;
    }

    
/**//// <summary>
    
/// 将一个文档库中的文档发送到指定文档库
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void btnCopy_Click(object sender, EventArgs e)
    
{
        SendDocument();
    }

    
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    
{
        
//e.Row.Cells[3].Attributes.Add("style", "display:none");
        e.Row.Cells[2].Attributes.Add("style""display:none");
    }

    
protected void Button2_Click(object sender, EventArgs e)
    
{
        ArrayList arylst 
= new ArrayList();

        
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
        
{
            
if (this.CheckBoxList1.Items[i].Selected)
            
{
                arylst.Add(
this.CheckBoxList1.Items[i].Value);
            }

        }


        
//给每个文档库中的一条设置用户权限
        SPRoleType[] types = new SPRoleType[] { SPRoleType.Administrator,SPRoleType.Contributor,SPRoleType.Reader,SPRoleType.WebDesigner };
        
for (int j = 0; j < arylst.Count; j++)
        
{
            AssignRight(
9this.txtName.Text.Trim(), types[int.Parse(arylst[j].ToString())]);
        }

    }

    
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    
{
        ViewState[
"FromPath"= this.TreeView1.SelectedNode.Value;
        BindGrid();
    }

    
protected void TreeView2_SelectedNodeChanged(object sender, EventArgs e)
    
{
        ViewState[
"ToPath"= this.TreeView2.SelectedNode.Value;
    }

    
protected void TreeView3_SelectedNodeChanged(object sender, EventArgs e)
    
{
        
//Session["DocLibName"] = this.TreeView3.SelectedNode.Value;
    }

    
protected void lnkSendMsg_Command(object sender, CommandEventArgs e)
    
{
        LinkButton lb 
= (LinkButton)sender;
        DataControlFieldCell dcf 
= (DataControlFieldCell)lb.Parent;
        GridViewRow gvr 
= (GridViewRow)dcf.Parent;
        GridView1.SelectedIndex 
= gvr.RowIndex;

        doAddMessageSendReceive(
301, DateTime.Now,gvr.Cells[2].Text,"301", gvr.Cells[3].Text);
    }


    
/**//// <summary>
    
/// 新增消息
    
/// </summary>

    protected void doAddMessageSendReceive(int receiveid,DateTime sendtime,string msgtitle,string to,string content)
    
{
        Yesidea.Model.Message_SendList modelMessage_SendList 
= new Yesidea.Model.Message_SendList();
        Yesidea.BO.Message_SendList boMessage_SendList 
= new Yesidea.BO.Message_SendList();

        modelMessage_SendList.Sender 
= receiveid;
        modelMessage_SendList.SendTime 
= sendtime;
        modelMessage_SendList.Title 
= msgtitle;
        modelMessage_SendList.Ricivers 
= to;
        modelMessage_SendList.MContent 
= content;
        modelMessage_SendList.Notes 
= "";

        
string[] arr = null;
        arr 
= GetSplitString(to, ",");

        boMessage_SendList.AddMessage(modelMessage_SendList, arr);
        Response.Write(
"<script language='javascript'>alert('发送成功');</script>");
    }


    
/**//// <summary>
    
/// 拆分字符串成字符串数组
    
/// </summary>
    
/// <param name="list"></param>
    
/// <param name="gap"></param>
    
/// <returns></returns>

    private string[] GetSplitString(string list, string gap)
    
{
        
char[] delimiter = gap.ToCharArray();
        
string[] report = null;
        
for (int i = 1; i <= list.Length; i++)   //把用逗号隔开的字符串拆分成字符串数组report   
        {
            report 
= list.Split(delimiter, i);
        }

        
return report;
    }

    
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
{
        
this.GridView2.PageIndex = e.NewPageIndex;
        
this.GridView2.DataKeyNames = new string[] "文档库ID" };
        
this.GridView2.DataSource = MyDataSource();
        
this.GridView2.DataBind();
    }


    
/**//// <summary>
    
/// 选择路径
    
/// </summary>
    
/// <param name="sender"></param>
    
/// <param name="e"></param>

    protected void ddlDocTitle2_SelectedIndexChanged1(object sender, EventArgs e)
    
{
        Url 
= this.ddlDocTitle2.SelectedItem.Value;
    }

    
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    
{
        
this.GridView1.PageIndex = e.NewPageIndex;
        
if (ViewState["FromPath"!= null)
        
{
            
this.GridView1.DataKeyNames = new string[] "文档库ID" };
            
this.GridView1.DataSource = CreateDataSource(ViewState["FromPath"].ToString());
            
this.GridView1.DataBind();
        }

    }

    
protected void Button1_ServerClick(object sender, EventArgs e)
    
{
        SPSite sps 
= yesinda.yesindakms.sharepoint.List.ListLib.findParamSite("/dept/gsb/"this.Context);
        sps.AllowUnsafeUpdates 
= true;
        SPWeb web 
= sps.OpenWeb();
        web.AllowUnsafeUpdates 
= true;
        
        
// Create folder as subcolumn
        string folderUrl = ColumnTreeBox1.CurrentValue.Trim();
        SPFolder parent 
= web.GetFolder("/dept/gsb/DocLib5/");
         Label1.Text 
= Label1.Text + parent.Url.ToString() + "<br>";
        
if (parent.Exists)
        
{
            SPList l 
= web.Lists.GetList(parent.ParentListId, true);
            SPDocumentLibrary doc 
= (SPDocumentLibrary)l;
            SPListItem item 
= l.Items.Add("/dept/gsb/DocLib5", SPFileSystemObjectType.Folder);
            Response.Write(siteUrl 
+ folderUrl);
            item[
"名称"= "fsfd";
            item.Update();
            
string parentUrl = parent.Url;
            
string currentUrl = parentUrl + "/" + name;

            
try
            
{
                SPList infoList 
= web.Lists["栏目信息表"];
                SPListItem newItem 
= infoList.Items.Add();
                newItem[
"全路径"= currentUrl;
                newItem[
"栏目名"= name;
                newItem[
"是否顶级"= false;
                
if (CheckBox2.Checked)
                    newItem[
"是否汇总"= true;
                
if (CheckBox3.Checked)
                    newItem[
"是否审核"= true;
                
if (!CheckBox4.Checked)
                    newItem[
"是否显示"= false;
                
if (CheckBox5.Checked)
                    newItem[
"URL"= TextBox2.Text;
                
//以上if语句省去else,因为列表项有默认值
                newItem.Update();
            }

            
catch (Exception ex)
            
{
                Response.Write(ex.Message);
            }

        }

    }

}




Trackback: http:
// tb.blog.csdn.net/TrackBack.aspx?PostId=1525216

你可能感兴趣的:(SharePoint)