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
}
}
Add a 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;
}
}
-
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; }} Commented Jan 27, 2013 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); Commented Jan 27, 2013 at 15:36
-
i get red at if (GetAttachmentsurls.Contains and Getattachmentsurls.add Commented Jan 27, 2013 at 15:36