I am using Devexpress, When I choose a valid file to upload it says "Object reference not set to an instance of an object." If I put the filepath and into into the database manually and add the file to folder where web.config is set to I can see the file and download it. this is the part of code that breaks when trying protected void DocumentUpload_OnFileUploadComplete(object sender, FileUploadCompleteEventArgs e) { if (!e.UploadedFile.IsValid) return; GridViewDetailRowTemplateContainer container = ((Control)sender).NamingContainer as GridViewDetailRowTemplateContainer; Int32 index = container.VisibleIndex; var orderId = Convert.ToInt32(ViewOrdersGridView.GetRowValues(index, ViewOrdersGridView.KeyFieldName)); var fileNumber = ViewOrdersGridView.GetRowValues(index, ElsaConstants.FileNumber).ToString(); var userId = Convert.ToInt32(Session[ElsaConstants.UserId]); string directory = ConfigurationManager.AppSettings[ElsaConstants.UploadDirectory]; if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } string fileType = Path.GetExtension(e.UploadedFile.FileName); string fileName = e.UploadedFile.FileName.Replace(fileType, string.Format("_{0}{1}", fileNumber, fileType)); string resultFilePath = directory + fileName; e.UploadedFile.SaveAs(resultFilePath, true);//MapPath using (var context = new ELSAEntities()) { var document = new Document { OrderId = orderId, DocumentPath = fileName, DateCreated = DateTime.Now, CreatedBy = userId }; context.Document.Add(document); context.SaveChanges(); } }<pre><pre><pre lang="c#">
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)