2

I'm attempting to retrieve the URL of the current document in a SharePoint 2010 document library so it can be added to an email in a SharePoint 2010 workflow.

Currently, I have the following code in a Utilities.cs file:

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;            

        }        

    }
}

In my workflow file (Workflow1.cs) with the same namespace I am trying to call the above method using the following line:

Item.File.AbsoluteUrl();

When I attempt to call the method I get "the name Item does not exist in the current context". Am I missing a reference? Any suggestions on how to retrieve the DecodedURL value so I can use it in my main workflow file would be greatly appreciated. Also, most of this code was copied from another post but I do not have enough points to comment on the original post.

user3400457
  • 61
  • 1
  • 6
  • 1
    There is no way for people on SO to know what type of object `Item` is, especially even if your compiler can't figure it out... More context could help. Also there is no points requirement to link to questions you took source from. – Alexei Levenkov Jun 30 '15 at 01:58
  • Hello Alexei, Thanks for the feedback. The original post can be found here: http://stackoverflow.com/questions/5216832/how-to-get-the-absolute-url-of-a-file-in-sharepoint-library . I'm referring to the second answer to the question in the above link. I will post additional code later today – user3400457 Jun 30 '15 at 19:22

1 Answers1

0

Since (based on this method) you already have retrieved the correct SPFile object you should be able to refer to the url property.

See: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.url(v=office.14).aspx

If you would like the absolute URL you can use the field EncodedAbsUrl on the SPFile (this also works with SPListItems):

Usage (assuming your SPFile object is called file):

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

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

Michael A
  • 9,480
  • 22
  • 70
  • 114
  • Hello ElvisLikeBear, thanks for the link but I believe the above approach gets the site-relative URL of the file and I was hoping to get the decoded absolute URL of the file by accessing the return variable DecodedURL . Any suggestions? – user3400457 Jun 30 '15 at 19:26
  • @user3400457 Sorry, you're correct. Updated my answer to reflect this! – Michael A Jun 30 '15 at 22:55
  • Thanks for the update but I need to invoke: public static string AbsoluteUrl(this SPFile File) in the workflow in order to retrieve the DecodedURL value. For instance something along the lines of: private void CodeActivity(SPFile File) { absoluteUrl = Utilities.AbsoluteUrl(File); } – user3400457 Jul 01 '15 at 23:27