0
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {      

            SPWeb web = SPContext.Current.Web;
            SPList list = web.Lists.TryGetList(DropDownListSelectCategory.SelectedItem.Value);

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
              HyperLink hp =new HyperLink();
              // want to display attachent here like hyperlink how do i do that= , i only want to have one attachment for every uploaded attachment
              //Example
              //Name:Simon
              //Age:25
              //Attachment: hello.jpg

              //Name:Arnold
              //Age:25
              //Attachment:jebiga.jpg
            }
     }
0

try below function....

just pass SPListItem object to below function, it returns attachment url from list item.

//set attachment url to hyperlink..
hyperlink.Text = "attachment name find from returned attachment url";
hyperlink.NavigateUrl = GetAttachmentUrls(objSPListItem)

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;
    }

}
  • private string GetAttachmentUrls(SPListItem oItem){ string path;try{ path = (from string file in oItem.Attachments orderby file select SPUrlUtility.CombineUrl(oItem.Attachments.UrlPrefix, file)).FirstOrDefault(); return path;} catch{ return string.Empty; }} – Batistuta Jan 27 '13 at 15:35
  • if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem){ HyperLink hp = new HyperLink(); foreach (SPListItem item in list.Items){ foreach (string currentAttachmentUrl in item.Attachments) { if (GetAttachmentUrls.Contains(currentAttachmentUrl)) { hp = new HyperLink(); hp.ID = e.Item.ItemIndex.ToString(); hp.Text = item.Attachments.UrlPrefix + currentAttachmentUrl; hp.NavigateUrl = currentAttachmentUrl; GetAttachmentUrls.Add(currentAttachmentUrl); – Batistuta Jan 27 '13 at 15:36
  • i get red at if (GetAttachmentsurls.Contains and Getattachmentsurls.add – Batistuta Jan 27 '13 at 15:36

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.