public long SaveListingDocuments(long listingID) { var serialization = new Serialization(); var listingsBA = new Listings(); var result = string.Empty; var resultlisting = 0; var lstDocuments = Session["ListingDocuments"] as List <ListingLoanDocuments>; if (lstDocuments != null && lstDocuments.Count > 0) { foreach (var tempfile in lstDocuments) { var TempDocumentPath = System.Configuration.ConfigurationManager.AppSettings["ListingTempDocumentPath"]; TempDocumentPath = TempDocumentPath + "/" + tempfile.DocumentType; var DocumentPath = System.Configuration.ConfigurationManager.AppSettings["ListingDocumentPath"] + "/" + listingID; DocumentPath = DocumentPath + "/" + tempfile.DocumentType; var folderExists = Directory.Exists(Server.MapPath(DocumentPath)); if (!folderExists) { Directory.CreateDirectory(Server.MapPath(DocumentPath)); } var TempserverPath = Server.MapPath(TempDocumentPath + "/" + tempfile.FileName); var ActualImagePath = Server.MapPath(DocumentPath + "/" + tempfile.FileName); var docpresent = System.IO.File.Exists(ActualImagePath); var tempPresent = System.IO.File.Exists(TempserverPath); if (!docpresent && tempPresent) { if (!tempfile.IsDeleted) { System.IO.File.Copy(TempserverPath, ActualImagePath); } } if (docpresent && tempfile.IsDeleted) { System.IO.File.Delete(Server.MapPath(DocumentPath + "/" + tempfile.FileName)); } //Save listing Documents in database Hashtable HashCriteria = new Hashtable(); HashCriteria.Add("FileName", tempfile.FileName); HashCriteria.Add("IsDeleted", tempfile.IsDeleted); HashCriteria.Add("ID", tempfile.id); HashCriteria.Add("DocumentTypeID", tempfile.DocumentTypeID); HashCriteria.Add("ListingID", listingID); HashCriteria.Add("UserID", userID); var actualCriteria = serialization.SerializeBinary((object)HashCriteria); result = Convert.ToString(listingsBA.SaveUploadedListingDocuments(actualCriteria)); resultlisting = Convert.ToInt32(serialization.DeSerializeBinary(Convert.ToString(result))); var res = System.IO.File.Exists(TempDocumentPath + "/" + tempfile.FileName); if (res) { System.IO.File.Delete(Server.MapPath(TempDocumentPath + "/" + tempfile.FileName)); } } } return(resultlisting); }