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.