Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

First i'm saving the attachment to a list & the url to a db. But when i want to get the url from a db and show it on a image control i dont get the image to be shown.

                    SPListItem item = myList.Items.Add();
                    item["Title"] = strUserName;
                    if(FileUploadEmployeeImg.PostedFile != null && FileUploadEmployeeImg.HasFile)
                    {
                        Stream fStream = FileUploadEmployeeImg.PostedFile.InputStream;
                        byte[] contents = new byte[fStream.Length];
                        fStream.Read(contents, 0, (int) fStream.Length);
                        fStream.Close();
                        fStream.Dispose();
                        SPAttachmentCollection attachments = item.Attachments;
                        string fileName = Path.GetFileName(FileUploadEmployeeImg.FileName);

                        attachments.Add(fileName, contents);
                    }

                    string listUrl = web.Url + "/" + myList.RootFolder.Url;
                    string attachmentUrl = listUrl + "/attachments/" + item.ID + "/" + FileUploadEmployeeImg.FileName;

                    item.Update();

                    //Lägger till employeen
                    var newEmp = new EMPLOYEE
                    {
                        image = attachmentUrl
                    };

                    db.AddToEMPLOYEES(newEmp);
                    db.SaveChanges();

The url that saves in the db is: http://wingtipserver/Lists/Knowit.Cv-ProfilePicturesListInstance/attachments/0/kiki.jpg, but the real url is: http://wingtipserver/Lists/Knowit.Cv-ProfilePicturesListInstance/attachments/1/kiki.jpg

So i guess it's the item.ID that doesn't work properly.

share|improve this question
ItemID of 0 shouldn't ever exist in SharePoint, you sure you got those URLs the right way round in your question? – James Love Mar 20 at 20:12

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.