0

我正在尝试编写一个将 xml 文件上传到 SharePoint 2010 中的列表的方法。为此,我有另一种方法,它DropDownList使用带有BaseType DocumentLibrary. DDL 填充得很好,只是它包含我无法上传到的库,例如“自定义报告”就是其中之一。

所以我基本上需要改进过滤器,所以它只显示“标准”文档库。

这是我填充的代码DropDownList

protected void initExportControlsForUploadingtoList()
{
    //Check if there are lists on the current website.
    if (SPContext.Current.Web.Lists != null && SPContext.Current.Web.Lists.Count > 0)
    {
        //Get the lists.
        SPListCollection currentsitelists = SPContext.Current.Web.Lists;

        //Reset the DropDownList holding the lists.
        ddlExportSelectList.Items.Clear();
        ddlExportSelectList.Items.Add("");

        //Populate the DDL with the lists' names.
        foreach (SPList list in currentsitelists)
        {
            if (!list.Hidden && list.BaseType == SPBaseType.DocumentLibrary)
            {
                ddlExportSelectList.Items.Add(list.Title);
            }
        }

        //Select the first item in the DDL, which is "empty".
        ddlExportSelectList.SelectedIndex = 0;
    }
    else
    {
        lblStatus.Text = "No lists found.";
    }
}

编辑:

错误详情:

System.ArgumentException“价值不在预期范围内。”

在 Microsoft.SharePoint.SPFolderCollection.get_Item(String urlOfFolder) 在 SiteCollectionTreeView.VisualWebPart1.MigrationTool.btnExportOK_Click(Object sender, EventArgs e)

错误发生在此代码块中(部分btnExportOK_Click(Object sender, EventArgs e)):

try
{
    //Get the folder with the corresponding list name as value from DropDownList.
    SPFolder librarytouploadto = SPContext.Current.Web.Folders[ddlExportSelectList.SelectedValue];
}
catch (Exception ex)
{
    lblStatus.Text = "Problem uploading to that list. Try another one or create a new one.";
    return;
}

编辑:

好的,如果我将 try 块更改为:

try
{
    //Get the folder with the corresponding list name as value from DropDownList.
    string url = SPContext.Current.Web.Lists[ddlExportSelectList.SelectedValue].DefaultDisplayFormUrl;
    librarytouploadto = SPContext.Current.Web.GetList(url).RootFolder;
}
catch (Exception ex)
{
    lblStatus.Text = "Problem uploading to that list. Try another one or create a new one.";
    return;      
}

有用。但现在我不确定我是否应该这样做。例如,“自定义报告”是用户应该能够将随机 xml 文件上传到的列表吗?或者只要用户对它感到满意并且知道他/她的文件在哪里,这真的不重要吗?

4

0 回答 0