public int SavePdfToDisk(HttpPostedFileBase mainFile, PdfFile pdf, string svrPdfPath) { try { bool saved = false; string pdfExt = string.Empty; string pdfGuid = string.Empty; bool hasResourceFile = mainFile != null && mainFile.ContentLength > 0; int res = 0; if (hasResourceFile) { string id = Guid.NewGuid().ToString(); pdfExt = System.IO.Path.GetExtension(mainFile.FileName); pdfGuid = String.Concat(id, pdfExt); string path = System.IO.Path.Combine(svrPdfPath, pdfGuid); bool isValidItem = pdfExt.ToLower() == ".pdf"; if (!isValidItem) { res = 1; } int sizeKb = Convert.ToInt32(Math.Round(Convert.ToDecimal(mainFile.ContentLength / 1024), 0)); int maxAllowedSize = Helpers.ConfigurationHelper.MaxUploadSizePdf(); if (sizeKb > maxAllowedSize) { res = res + 2; } if (isValidItem && (sizeKb <= maxAllowedSize)) { mainFile.SaveAs(path); IContentRepository repos = new ContentRepository(); pdf.PdfGuid = pdfGuid; saved = repos.CreatePdf(pdf); if (saved) { // Helpers.CacheHelper.RemoveObjectFromCache(Helpers.CacheHelperKeys.CK_ALL_PAGES); } } } return(res); } catch (Exception) { throw; } }