Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
    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
            }
     }
share|improve this question
add comment

1 Answer

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

}
share|improve this answer
    
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; }} –  Martin 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); –  Martin Jan 27 '13 at 15:36
    
i get red at if (GetAttachmentsurls.Contains and Getattachmentsurls.add –  Martin Jan 27 '13 at 15:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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