【问题标题】:SharePoint 2010 Custom List and AttachmentsSharePoint 2010 自定义列表和附件
【发布时间】:2014-12-15 11:07:37
【问题描述】:

我创建了包含几列的自定义列表,即:

Title
Description
HrefLink

并且可以选择将附件上传到列表项。

我的场景如下,从列表中获取数据并使用超链接打印列表中的数据。在这里,对于超链接,我应该附上任何附件,否则请拉 HrefLink 字段值。

如何查找列表项是否有附件,如何拉取附件路径并打印?

【问题讨论】:

  • 您使用的是什么 API?服务器端,客户端?

标签: sharepoint-2010 attachment custom-lists sharepoint-api


【解决方案1】:

我已使用以下登录名获取附件并打印为文字:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
     using (SPSite currentSite = new SPSite(siteUrl))
         {
             using (SPWeb currentWeb = currentSite.OpenWeb())
                    {

                        /*Footer - Hotspot Links */
                        //Define string builder to attach the fetched content
                        StringBuilder strFooterHotspotLinks = new StringBuilder();

                        SPList lstFooterHotspotLinks = currentWeb.Lists["Footer Hotspot Links"];

                        //Difine list query
                        SPQuery spQryFooterHotspotLinks = new SPQuery();
                        spQryFooterHotspotLinks.Query = "<OrderBy><FieldRef Name='Hotspot_x0020_Order' Ascending='True' /></OrderBy>";
                        spQryFooterHotspotLinks.RowLimit = 5;

                        SPListItemCollection lstItmFooterHotspotLinks = lstFooterHotspotLinks.GetItems(spQryFooterHotspotLinks);

                        int lnkCount = 1;

                        if (lstItmFooterHotspotLinks.Count > 0)
                        {
                            foreach (SPListItem itmFooterHotspotLinks in lstItmFooterHotspotLinks)
                            {

                                String qlAttachmentAbsUrl = itmFooterHotspotLinks.Attachments.UrlPrefix;    //gets the containing directory URl
                                SPAttachmentCollection qlAttachments = itmFooterHotspotLinks.Attachments;   //check the attachment exists or not for list item

                                //If list attachmetns are existing
                                if (qlAttachments.Count > 0)
                                {
                                    //Loop the list to find the attachments exist ot not and attach to the link
                                    foreach (String qlAttachmentName in qlAttachments)
                                    {
                                        strFooterHotspotLinks.Append("<li><a href='" + qlAttachmentAbsUrl + qlAttachmentName + "'><span class='icn-" + lnkCount + "'></span>" + itmFooterHotspotLinks["Hotspot Title"] + "</a></li>");
                                        lnkCount++;
                                    }
                                }
                                else
                                {
                                    strFooterHotspotLinks.Append("<li><a href='" + itmFooterHotspotLinks["Hotspot Link"] + "'><span class='icn-" + lnkCount + "'></span>" + itmFooterHotspotLinks["Hotspot Title"] + "</a></li>");
                                    lnkCount++;
                                }
                            }
                        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    相关资源
    最近更新 更多