SPSecurity.RunWithElevatedPrivileges(delegate() {
oWeb.AllowUnsafeUpdates = true; SPList oList = oWeb.Lists[sRequestList]; SPListItem oVoucher = oList.GetItemById(Convert.ToInt32(Request.QueryString["RequestNo"])); oVoucher.Delete();
oList.Update(); oWeb.AllowUnsafeUpdates = false;
});
Saturday, 25 April 2015
Delete list item programmatically by id
Save file in local drive
try {
SPSecurity.RunWithElevatedPrivileges(delegate() { oFile = @"filepath"; byte[] binFile = oFile.OpenBinary(); string path = @"D:\Library\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string tepmPath = path + oFile.Name; if (File.Exists(tepmPath)) { File.Delete(tepmPath); } using (FileStream fs = File.Create(tepmPath)) { fs.Write(binFile, 0, binFile.Length); fs.Close(); } }); }
catch (Exception ex)
{
//exception handleing here
}
To check file extensions while uploading
javascript:
var validFilesTypes = ["xls", "xlsx"]; function CheckExtension(file) { /*global document: false */ var filePath = file.value; var ext = filePath.substring(filePath.lastIndexOf('.') + 1).toLowerCase(); var isValidFile = false; for (var i = 0; i < validFilesTypes.length; i++) { if (ext == validFilesTypes[i]) { isValidFile = true; break; } } if (!isValidFile) { file.value = null; alert("Invalid File. Valid extensions are:\n\n" + validFilesTypes.join(", ")); file.value=""; } return isValidFile; }
aspx page:
<asp:FileUpload ID="fuFile" runat="server" onchange="return CheckExtension(this);" />