簡體   English   中英

調用靜態方法以獲取SharePoint 2010文檔的絕對URL

[英]Call static method to get absolute URL of SharePoint 2010 document

我正在嘗試在SharePoint 2010文檔庫中檢索當前文檔的URL,以便可以將其添加到SharePoint 2010工作流中的電子郵件中。

當前,我在Utilities.cs文件中具有以下代碼:

namespace WorkflowProject1.Workflow1
{
    public static class Utilities
    {
        public static string AbsoluteUrl(this SPFile File)
        {
            string EncodedUrl = File.Item[SPBuiltInFieldId.EncodedAbsUrl].ToString();
            string DecodedURL = SPEncode.UrlDecodeAsUrl(EncodedUrl);
            return DecodedURL;            

        }        

    }
}

在具有相同名稱空間的工作流文件(Workflow1.cs)中,我嘗試使用以下行調用上述方法:

Item.File.AbsoluteUrl();

當我嘗試調用該方法時,我得到“名稱Item在當前上下文中不存在”。 我是否缺少參考? 非常感謝您提供有關如何檢索DecodedURL值以便我可以在主工作流程文件中使用的任何建議。 另外,大部分代碼是從另一篇文章中復制的,但是我沒有足夠的觀點來評論原始文章。

由於(基於此方法)您已經檢索了正確的SPFile對象,因此您應該能夠引用url屬性。

請參閱: https : //msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spfile.url(v=office.14).aspx

如果您想要絕對URL,則可以在EncodedAbsUrl上使用字段EncodedAbsUrl(這也適用於SPListItems):

用法(假設您的SPFile對象稱為file ):

string absoluteUrl = (string) file.Item[SPBuiltInFieldId.EncodedAbsUrl];

文檔: https : //msdn.microsoft.com/EN-US/LIBRary/microsoft.sharepoint.spbuiltinfieldid.encodedabsurl.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM