在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
... {
定义变量和属性#region定义变量和属性
privateSPListlist9;
privateSPListItemCollectionitems;
publicstringUrl=String.Empty; //保存文档库根文件夹路径
publicstringHostName=String.Empty;//存放主机名

privatestringsiteUrl="/dept/gsb/";
publicstringSiteUrl
...{
get...{returnthis.siteUrl;}
set...{siteUrl=value;}
}

#endregion


protectedvoidPage_Load(objectsender,EventArgse)
...{
if(!IsPostBack)
...{
//绑定DropDownList控件
BindControl();
//绑定TreeView控件
TreeViewBind(this.TreeView1);
TreeViewBind(
this.TreeView2);
//AddUserTreeNode(this.TreeView3);
//绑定GridView数据控件
BindGrid();

HostName
=Request.UserHostName;
}

}


为TreeView添加节点#region为TreeView添加节点
/**////<summary>
///为TreeView添加节点
///</summary>
///<paramname="parentFolder"></param>
///<paramname="parentNode"></param>

privatevoidAddChild(SPFolderparentFolder,TreeNodeparentNode)
...{
if(parentFolder.SubFolders.Count==0)
return;
foreach(SPFolderfinparentFolder.SubFolders)
...{
if(f.Name!="Forms"&&f.Name.IndexOf("_")!=0)
...{
TreeNodechild
=newTreeNode(f.Name,f.ServerRelativeUrl);
parentNode.ChildNodes.Add(child);
AddChild(f,child);
}

}

}

#endregion


绑定TreeView控件#region绑定TreeView控件
/**////<summary>
///绑定TreeView控件
///</summary>

protectedvoidTreeViewBind(TreeViewtreeview)
...{
SPSitesps
=yesinda.yesindakms.sharepoint.List.ListLib.findParamSite("/dept/gsb/",this.Context);
sps.AllowUnsafeUpdates
=true;
SPWebspw
=sps.OpenWeb();
spw.AllowUnsafeUpdates
=true;

SPWebCollectionsites
=sps.AllWebs;
foreach(SPWebsiteinsites)
...{
SPListCollectionlists
=site.Lists;
foreach(SPListlistinlists)
...{
if(list.BaseType==SPBaseType.DocumentLibrary&&list.BaseTemplate!=SPListTemplateType.ListTemplateCatalog
&&list.BaseTemplate==SPListTemplateType.DocumentLibrary)
...{
list9
=spw.Lists[list.Title];
items
=list9.Items;
SPFolderroot
=list.RootFolder;
TreeNoderootNode
=newTreeNode(list.Title,root.Url);
treeview.Nodes.Add(rootNode);
AddChild(root,rootNode);
}

}

}

}

#endregion


创建数据源#region创建数据源
/**////<summary>
///创建数据源
///</summary>
///<returns></returns>

ICollectionCreateDataSource()
...{
DataTabledt
=newDataTable("mytable");//创建一个名为mytable的DataTable对象形
DataColumndc=newDataColumn();//创建一个列对象
dc.DataType=System.Type.GetType("System.String");//指定该列的数据类型
dc.Caption="DocID";//设置列的标题
dc.ColumnName="文档库ID";//设置列集合对象中的列的名称,datagrid中显示该列名.
dt.Columns.Add(dc);//将该列对象加入到表mytable的列集合中
//普通列
DataColumndc1=newDataColumn();
dc1.DataType
=System.Type.GetType("System.String");
dc1.AllowDBNull
=false;
dc1.Caption
="Path";
dc1.ColumnName
="路径";
dt.Columns.Add(dc1);

DataColumndc2
=newDataColumn();
dc2.DataType
=System.Type.GetType("System.String");
dc2.AllowDBNull
=false;
dc2.Caption
="FullPath";
dc2.ColumnName
="完整路径";
dc2.DefaultValue
=25;
dt.Columns.Add(dc2);

SPSitesps
=yesinda.yesindakms.sharepoint.List.ListLib.findParamSite("/dept/gsb/",this.Context);
sps.AllowUnsafeUpdates
=true;
SPWebspw
=sps.OpenWeb();
spw.AllowUnsafeUpdates
=true;

SPWebCollectionsites
=sps.AllWebs;
foreach(SPWebsiteinsites)
...{
SPListCollectionlists
=site.Lists;
foreach(SPListlistinlists)
...{
if(list.BaseType==SPBaseType.DocumentLibrary&&list.BaseTemplate!=SPListTemplateType.ListTemplateCatalog
&&list.BaseTemplate==SPListTemplateType.DocumentLibrary)
...{
if(dt!=null)
...{
DataRowdr
=dt.NewRow();
dr[
0]=list.Title;
dr[
1]=list.RootFolder.ServerRelativeUrl;
dr[
2]="http://"+sps.HostName+list.RootFolder.ServerRelativeUrl;
dt.Rows.Add(dr);
}

}

}

}


DataViewdv
=newDataView(dt);
returndv;
}


/**////<summary>
///根据路径,动态创建数据源
///</summary>
///<returns></returns>

ICollectionCreateDataSource(stringfolderpath)
...{
DataTabledt
=newDataTable("mytable");//创建一个名为mytable的DataTable对象形
DataColumndc=newDataColumn();//创建一个列对象
dc.DataType=System.Type.GetType("System.Int32");//指定该列的数据类型
dc.AutoIncrement=true;//该列为自动增涨列
dc.AutoIncrementSeed=1;//初始值
dc.AutoIncrementStep=2;//增量
dc.Caption="DocID";//设置列的标题
dc.ColumnName="文档库ID";//设置列集合对象中的列的名称,datagrid中显示该列名.
dt.Columns.Add(dc);//将该列对象加入到表mytable的列集合中
//普通列
DataColumndc1=newDataColumn();
dc1.DataType
=System.Type.GetType("System.String");
dc1.AllowDBNull
=false;
dc1.Caption
="Path";
dc1.ColumnName
="路径";
dt.Columns.Add(dc1);

DataColumndc2
=newDataColumn();
dc2.DataType
=System.Type.GetType("System.String");
dc2.AllowDBNull
=false;
dc2.Caption
="FullPath";
dc2.ColumnName
="完整路径";
dc2.DefaultValue
=25;
dt.Columns.Add(dc2);

SPSitesps
=yesinda.yesindakms.sharepoint.List.ListLib.findParamSite("/dept/gsb/",this.Context);
sps.AllowUnsafeUpdates
=true;
SPWebspw
=sps.OpenWeb();
spw.AllowUnsafeUpdates
=true;

SPFolderf
=spw.GetFolder(folderpath);

foreach(SPFilefilecolor: #0
分享到:
评论

你可能感兴趣的:(UI,Web,Microsoft,F#,SharePoint)