SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

hi i am using built in attachment in a list i have created an textbox and a button and i would like to show the url of the attachment in the textbox TextBox1.Text = customer["Attachments"].ToString();

SPWeb web = SPContext.Current.Web;

        SPList customerList = web.Lists.TryGetList("MyList");
        if (customerList != null)
            SPQuery query = new SPQuery();
            query.Query =
                    "<Where><BeginsWith><FieldRef Name='ProductNumber' /><Value Type='Text'>{0}</Value></BeginsWith></Where>",
            query.RowLimit = 10;

            SPListItemCollection items = customerList.GetItems(query);

when writing like this i get in the textbox true... whats the problem???enter image description here

this solved my problem...

 SPAttachmentCollection collAttachments = customer.Attachments;

                if (collAttachments.Count > 0)
                    for (int i = 0; i < collAttachments.Count; i++)


share|improve this question
up vote 1 down vote accepted

If I am not mistaken, customer["Attachments"] will return for you an SPAttachmentCollection, so converting that to string is probably not what you want.

Please try something like this to obtain the URL of each attached file from the attachment collection of a list item.

SPAttachmentCollection collAttachments = oListItem.Attachments;

for (int i=0; i<collAttachments.Count; i++)
   TextBox1.Text += collAttachments[i];

I hope this is what you were looking for :)


share|improve this answer
hi yes thanks , but i get the problem then every time i press make changes is makes duplicates for me.. – Batistuta Dec 6 '12 at 11:25
Ok, the one above was just a sample. If you want it translated to your particular case, I think it should be something like this: get rid of the for cycle. Just use: TextBox1.Text = collAttachments[0]; Of course, checking first if (collAttachments.Count > 0) wouldn't hurt :) – Norbert Dec 6 '12 at 11:35

Your Answer


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.