Private void uploadfiletolist ()
{
Try
{
Spsite site = spcontrol. getcontextsite (context );
Spweb web = site. rootweb;
Spfoldercollection addfold = web. Folders;
Spfilecollection destfiles = web. getfolder ("agendamatterdocuments"). files;
Int Index = docfile. postedfile. filename. lastindexof ("\\");
String strfilename = docfile. postedfile. filename. substring (index + 1 );
Splist list = web. Lists ["agendamatterdocuments"];
Spview view = List. views ["all documents"];
Splistitemcollection listitems = List. getitems (View );
If (this. ck_overwrite.checked)
{
Foreach (splistitem SPL in listitems)
{
If (SPL. Name = strfilename)
{
SPL. Delete ();
}
}
}
Httppostedfile file = docfile. postedfile;
Byte [] docby = new byte;
Stream filestream = file. inputstream;
Filestream. Read (docby, 0, file. contentlength );
String desurl = web. getfolder ("agendamatterdocuments"). url + "/" + strfilename;
Destfiles. Add (desurl, filestream );
splist listadd = web. lists ["agendamatterdocuments"];
spview viewadd = listadd. views ["all documents"];
splistitemcollection listitems1 = List. getitems (viewadd);
int fileid = 0;
foreach (splistitem SPL in listitems1)
{< br> If (SPL. name = strfilename)
{< br> fileid = SPL. ID;
}< BR >}
Spdocumentlibrary doclibrary = (spdocumentlibrary) List;
Spview view1 = List. views [0];
Spfile file1 = doclibrary. getitembyid (fileid). file;
Splistitem newitem = file1.item;
Newitem ["matter"] = This. ddl_matter.selecteditem.text;
Newitem ["title"] = this.txt _ title. text;
Newitem ["documentnumber"] = This. textbox1.text;
Newitem ["doumentaddtionaldescription"] = This. textbox2.text;
Newitem ["documentshortdescription"] = this.txt _ shortdesc. text;
Newitem. Update ();
}
Catch (exception ex)
{
Response. Write ("<SCRIPT> alert ('" + ex. Message + "'); </SCRIPT> ");
}
}