Hi all
I developed a custom sharepoint field that uploads a file in a specific document library and stores the url of the file after saqving it as the value of the field.
the problem is that the uploaded file is stored twice one in the library as I want and the other as an attachment with the item in the list that has this field.
how can I avoid savig the file as an attachment ?
thank you
Edit: Here's the Code:
public override void UpdateFieldValueInItem()
{
string name="";
if(fileUploader.PostedFile.FileName!="")
{
//method to store the posted file in a certain library
string x= UploadFile(this.Web, fileUploader.PostedFile.FileName,fileUploader.FileName,out name);
//Stores The URL and the name of the file
SPFieldUrlValue urlValue = new SPFieldUrlValue() {
Description=name,
Url=x
};
this.Value = urlValue;
this.ItemFieldValue = urlValue;
}
}
UploadFile method
string UploadFile(SPWeb web,string path,string fileName,out string name)
{
UploadField uf = (UploadField)base.Field;
SPList docsList = web.Lists[uf.StoreList];
SPFolder folder = web.GetFolder(docsList.RootFolder.UniqueId);
byte[] contents = File.ReadAllBytes(path);
SPFile file= folder.Files.Add(folder.Url + "/" + fileName, contents);
//folder.Update();
SPListItem item = docsList.Items[file.UniqueId];
name = item["Name"].ToString();
return getItemURL(item);
}