我目前正在开发一个 Outlook 插件,这是我第一次做面向对象的事情,我是一个初学者,但既然你们都曾在某个时候在那里,我想你们都可以对我有同情心:) 不要评判我是否我问的方式可能会让人觉得很愚蠢。
我有一个 Outlook 插件,它将电子邮件从 Outlook 保存到 SharePoint,我需要的是一个SharePoint 库树视图,一旦按下Save To SharePoint按钮就会显示(应该看起来像这样TreeView)
我的问题这里有没有人有这方面的经验,有没有人做过类似的事情,任何人都可以帮助我通过任何提示获得先机吗?我提前感谢大家,并期待您的精彩回答。
到目前为止我所拥有的是这个,但我需要一些关于如何使用它的提示:
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
TreeView treeView;
TreeNode rootNode;
public WebPart1()
{
}
protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
// render the control
base.RenderContents(writer);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
// get the current site
SPSite currentSite = SPContext.Current.Site;
using (SPWeb currentWeb = currentSite.OpenWeb())
{
// set the tree view properties
treeView = new System.Web.UI.WebControls.TreeView();
treeView.ShowLines = true; // show lines
treeView.ExpandDepth = 0; // expand non
SPList list = currentWeb.Lists["All Programs"];
// build the tree
rootNode = new System.Web.UI.WebControls.TreeNode(list.Title, "",
"", list.RootFolder.ServerRelativeUrl.ToString(), "");
// loop down the tree
GetFolder(list.RootFolder, rootNode, list);
// add the root node to tree view
treeView.Nodes.Add(rootNode);
}
this.Controls.Add(treeView);
base.CreateChildControls();
}
public void GetFolder(SPFolder folder, TreeNode rootNode, SPList list)
{
// create a new node
TreeNode newNode = new System.Web.UI.WebControls.TreeNode(folder.Name, "",
"~/_layouts/images/itdl.gif",
folder.ServerRelativeUrl.ToString(), "");
try
{
// don't add the forms folder
if (folder.Name != "Link")
{
// loop through all child folders
foreach (SPFolder childFolder in folder.SubFolders)
{
// don't add the forms folder
if (childFolder.Name != "Link")
{
TreeNode trn =
new System.Web.UI.WebControls.TreeNode(childFolder.Name, "",
"", childFolder.ServerRelativeUrl.ToString(), "");
newNode = GetItems(childFolder, trn);
// add the new node to the tree
rootNode.ChildNodes.Add(newNode);
}
}
}
}
catch { }
}
public TreeNode GetItems(SPFolder folder, TreeNode node)
{
//Get Items from childFolder
SPQuery qry = new SPQuery();
qry.Folder = folder;
SPWeb web = null;
web = folder.ParentWeb;
SPListItemCollection ic = web.Lists[folder.ParentListId].GetItems(qry);
foreach (SPListItem subitem in ic)
{
if (subitem.Folder != null) //Is Subfolder
{
// create a new node for a subfolder and add items to it
TreeNode childNode =
new System.Web.UI.WebControls.TreeNode(subitem.Folder.Name);
node.ChildNodes.Add(GetItems(subitem.Folder, childNode));
}
if (subitem.Folder == null)
{
TreeNode trn1 = new System.Web.UI.WebControls.TreeNode(
subitem["Title0"].ToString());
node.ChildNodes.Add(trn1);
}
}
return node;
}
}