Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This only show the current attachment in the repeater i want it to show old also

  SPWeb web = SPContext.Current.Web;

            SPList list = web.Lists.TryGetList(DropDownListSelectCategory.SelectedItem.Value);


            HyperLink hp = new HyperLink();
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                SPListItemCollection oListItems = list.Items;
                foreach (SPListItem item in oListItems)
                {
                    SPAttachmentCollection collAttachments = item.Attachments;




                    foreach (var attachment in collAttachments)
                    {

                        hp.NavigateUrl = collAttachments.UrlPrefix + attachment;

                        hp.Text = collAttachments.UrlPrefix + attachment;
                        hp.ID = e.Item.ItemIndex.ToString(CultureInfo.InvariantCulture); 
                    }



                }
            }
            e.Item.Controls.Add(hp); 
        }
share|improve this question
    
What do you mean? The attachments does not support versions. –  Alexander Jan 28 '13 at 12:53
    
when uploading attachment to list i want it to show it in the repeater , the first uploaded attachments show up. When uploading second attachment it overrides the first attachment and show the second attachment in repeater so i get the newest attachment in first and second, but i want to show only every singel attachment that i upload so if i upload 10 attachment i want it to display all the attachment in the repeater –  Martin Jan 28 '13 at 12:55
    
Have you added the same file as secondary attachment? –  Alexander Jan 28 '13 at 12:59
    
no i have not.... –  Martin Jan 28 '13 at 13:07
    
Please could you edit your question with that additional information? - it will help people using the site in the future. Thanks. –  SPDoctor Jan 28 '13 at 21:23
add comment

1 Answer 1

Create Hyperlink column inside attachment loop and add it in control collection like this:

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList(DropDownListSelectCategory.SelectedItem.Value);
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
    SPListItemCollection oListItems = list.Items;
    foreach (SPListItem item in oListItems)
    {       
        SPAttachmentCollection collAttachments = item.Attachments;
        foreach (var attachment in collAttachments)
        {
            HyperLink hp = new HyperLink();
            hp.NavigateUrl = collAttachments.UrlPrefix + attachment;
            hp.Text = collAttachments.UrlPrefix + attachment;
            hp.ID = e.Item.ItemIndex.ToString(CultureInfo.InvariantCulture); 
            e.Item.Controls.Add(hp); 
        }
    }
}
share|improve this answer
    
use SPUrlUtility.CombineUrl to combine urls –  Alexander Jan 28 '13 at 13:00
    
Nadeem YouSuf Not it show both attachment in i only want it to show one attachmen for every splistitem that i upload. //Example //Name:Simon //Age:25 //Attachment: hello.jpg //Name:Arnold //Age:25 //Attachment:jebiga.jpg –  Martin Jan 28 '13 at 13:04
    
In that case, as Alexander mentioned above, Attachments do not support versions. You can have many attachments, but only 1 version each. –  Andy Burns Jan 28 '13 at 13:08
    
okej , so how should i do? I want to upload a image to splist and then display it in a repeater? –  Martin Jan 28 '13 at 13:11
1  
the element of document library is a file with meta info. In your case it's an image. You can create you own content type based on picture library content type with needed columns. Also do not forget to use @ before my name, in other case I do not receive notifications. –  Alexander Jan 28 '13 at 13:23
show 3 more comments

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.