void btnSubmit_Click(object sender, EventArgs e)
{
try
{
//FileInfo[] fileinfo;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://vsr00a027-02:44712/"))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
Stream StreamUpload = null;
if (UploadDoc.HasFile)
{
StreamUpload = UploadDoc.PostedFile.InputStream;
}
//fileinfo = StreamUpload.GetType("*.doc");
SPList doc = web.Lists["Shared Documents"];
SPListItemCollection listItems = doc.Items;
SPListItem Item = listItems.Add();
//string Getfiles = Item.GetType("*.doc,*.txt");
//foreach (FileInfo f in fileinfo)
//{
String[] allowedExtension = { ".doc", ".docx", ".xlsx", ".txt" };
string ext = System.IO.Path.GetExtension(UploadDoc.PostedFile.FileName);
bool fileUpload = false;
for (int i = 0; i < allowedExtension.Length; i++)
{
if (ext == allowedExtension[i])
{
fileUpload = true;
break;
}
}
if (fileUpload)
{
SPFile UploadDocument = doc.RootFolder.Files.Add(UploadDoc.FileName, StreamUpload);
UploadDocument.Item.Update();
DisplayMessage("Document has been Added Successfully ", MessageType.Information);
}
else
{
DisplayMessage("Document Could not be Added! ", MessageType.Warning);
}
}
}
});
}
catch (Exception ex)
{
DisplayErroMessage(ex);
}
}
No comments:
Post a Comment