9

How to get attachment full URL programmatically From SharePoint list item?

Explanation:

I have adding new item with attachment. Now I have to bind that attachment link to grid. When click on that link Attachment should be open.

How can I get Attachment URL of that item?

10

I found answer for my question.

private string GetAttachmentUrls(SPListItem oItem)
{

        string path = string.Empty;

        try

        {

            path = (from string file in oItem.Attachments
                              orderby file
                              select SPUrlUtility.CombineUrl(oItem.Attachments.UrlPrefix, file)).FirstOrDefault();
            return path;
        }
        catch
        {
            return string.Empty;
        }

    }
| improve this answer | |
  • can you please give a bit explanation of this code? – Madhav Jun 16 '16 at 12:22
0

I did it in this way:

    private string GetAttachmentURL(SPAttachmentCollection attchmentcollection) {
        string URL="#";
        foreach (var item in attchmentcollection)
        {
            URL = attchmentcollection.UrlPrefix + item;
            break;
        }

        return URL;
    }
| improve this answer | |
-1

Try using below code:

string attachmentURL = splistitem.Attachments.UrlPrefix + splistitem.Attachments[0];

Regards,

Nabeel

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.