Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net c#文件上载工作正常,但在服务器中部署时出错_C#_Asp.net - Fatal编程技术网

asp.net c#文件上载工作正常,但在服务器中部署时出错

asp.net c#文件上载工作正常,但在服务器中部署时出错,c#,asp.net,C#,Asp.net,文件上传在本地运行正常,但在服务器中部署时出错。 错误消息是 “/”应用程序中出现服务器错误。 对象引用未设置为对象的实例。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源 异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例 源错误: 在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别 堆栈跟踪: [NullReferenceExce

文件上传在本地运行正常,但在服务器中部署时出错。 错误消息是

“/”应用程序中出现服务器错误。 对象引用未设置为对象的实例。 描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例

源错误:

在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别

堆栈跟踪:

[NullReferenceException:对象引用未设置为对象的实例。] Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionHandlingConfigurationView.GetExceptionPolicyData(字符串policyName)+186 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.GetConfiguration(字符串id,IConfigurationSource configurationSource)+102 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyCustomFactory.CreateObject(IBuilderContext上下文、字符串名称、IConfigurationSource配置源、ConfigurationReflectionCache reflectionCache)+94 Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy.Prebuild(IBuilderContext上下文)+325 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext上下文)+138

[BuildFailedException:当前生成操作(生成密钥生成密钥[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl,UIExceptionPolicy])失败:对象引用未设置为对象的实例。(策略类型ConfiguredObjectStrategy,索引2)] Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext上下文)+498 Microsoft.Practices.ObjectBuilder2.Builder.Building(IReadWriteLocator定位器、ILifetimeContainer生存期、IPolicyList策略、IStrategyChain策略、对象构建键、对象存在)+65 Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.Building(IReadWriteLocator、ILifetimeContainer lifetimeContainer、字符串id、IConfigurationSource配置源)+729 Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.LocatorNameTypeFactoryBase`1.Create(字符串名称)+187 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception Exception,String policyName,ExceptionPolicyFactory)+90

[ExceptionHandlingException:当前生成操作(生成密钥生成密钥[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl,UIExceptionPolicy])失败:对象引用未设置为对象的实例。(策略类型ConfiguredObjectStrategy,索引2)] Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.GetExceptionPolicy(Exception Exception,String policyName,ExceptionPolicyFactory)+494 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle,字符串policyName,ExceptionPolicyFactory policyFactory)+75 Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle,String policyName)+255 e:\PROJECT\DEVELOPMENT\WEBSITE\FOCUS-TUTORIAL\Focustutorial\MFBMS.Web\Focuspages\FileUploader.aspx.cs:185中的MFBMS.Web.Focuspages.Videouploader.btNuploAddDocument(对象发送者,事件参数e) System.Web.UI.WebControls.Button.OnClick(EventArgs e)+11594496 System.Web.UI.WebControl.Button.RaisePostBackEvent(String eventArgument)+274 System.Web.UI.Page.ProcessRequestMain(布尔includeStagesBeforeAsyncPoint,布尔IncludeStagesSafterAsyncPoint)+1964

)

下面是我尝试的代码

protected void btnUploadDocument(object sender, EventArgs e)
    {
        try
        {
            string PathToSave = "";
            string FolderLocation = "";
            string FileName = "";
            string PathToDB = "";
            string FileType = "";
           
            if (!DocumentFileUpload.HasFile)
            {
                DocumentFileUpload.Focus();
                lblUploadMsg.Visible = true;
                lblUploadMsg.Text = "Select File Name.";
                lblUploadMsg.Focus();
                lblUploadMsg.CssClass = "FailedAlert";
                return;
            }
            else
            {
                FileUploaderBO objBO = new FileUploaderBO();
                FileUploaderData objdata = new FileUploaderData();

                //****** FOR SAVING IMAGE TO DATABASE******//
                //int length = DocumentFileUpload.PostedFile.ContentLength;
                //byte[] imgbyte = new byte[length];
                //HttpPostedFile img = DocumentFileUpload.PostedFile;
                //img.InputStream.Read(imgbyte, 0, length);
                //objdata.ByteImage = imgbyte;
                //****** End FOR SAVING IMAGE TO DATABASE******//

                FileType = ddlFileType.SelectedItem.Text;
                FolderLocation = Server.MapPath(@"~/FileFolder/" + FileType + "/");
                if (!Directory.Exists(FolderLocation))
                {
                    Directory.CreateDirectory(FolderLocation);
                }
                PathToSave = Server.MapPath(@"~/FileFolder/" + FileType + "/");

                FileName = DocumentFileUpload.FileName;
                PathToDB = "~/FileFolder/" + FileType + "/" + FileName;
                PathToDB = "~/FileFolder/" + FileType + "/" + FileName;

                string fileCheck = PathToSave + FileName;
                string tempFileToCheck = "";
                if (System.IO.File.Exists(fileCheck))
                {
                    int counter = 2;
                    while (System.IO.File.Exists(fileCheck))
                    {
                        tempFileToCheck = counter.ToString() + FileName;
                        fileCheck = PathToSave + tempFileToCheck;
                        counter++;
                        FileName = tempFileToCheck;
                        lblUploadMsg.Text = "A file with the same name is already exist." + "<br/> your file was saved as" + FileName;
                        lblUploadMsg.Focus();
                        lblUploadMsg.CssClass = "FailedAlert";
                    }
                }
                else
                {
                    PathToSave += FileName;
                    DocumentFileUpload.SaveAs(PathToSave);
                }

                objdata.FileTypeID = Convert.ToInt32(ddlFileType.SelectedValue == "" ? "0" : ddlFileType.SelectedValue);
                objdata.FileTypeName = ddlFileType.SelectedItem.ToString();
                objdata.FileName = FileName;
                objdata.FilePath = PathToDB;
                objdata.FileTitle = txtTitle.Text == "" ? null : txtTitle.Text;
                objdata.FileDecription = txtDecription.Text == "" ? null : txtDecription.Text;

                List<FileUploaderData> DataList = new List<FileUploaderData>();
                DataList = objBO.UpdateUploadFile(objdata);
                if (DataList.Count > 0)
                {
                    if (DataList[0].SQLOutput == 1)
                    {
                        lblUploadMsg.Visible = true;
                        lblUploadMsg.Text = "Uploaded Successfully.";
                        lblUploadMsg.Focus();
                        lblUploadMsg.CssClass = "SuccessAlert";
                    }
                    else if (DataList[0].SQLOutput == 2)
                    {
                        lblUploadMsg.Visible = true;
                        lblUploadMsg.Text = "Uploaded Update Successfully.";
                        lblUploadMsg.Focus();
                        lblUploadMsg.CssClass = "SuccessAlert";
                    }
                }
                else
                {
                    lblUploadMsg.Focus();
                    lblUploadMsg.Visible = true;
                    lblUploadMsg.Text = "Not Uploaded due to system error.";
                    lblUploadMsg.CssClass = "FailedAlert";
                }
            }
        }
        catch (Exception ex)
        {
            HandlePolicyException.ExceptionHandler(HandlePolicyException.PolicyName.UIExceptionPolicy, ex, "1000001");
            LogManager.LogError(ex, EnumErrorSource.Web);
            MessageAlert_.ShowMessage(ex, "system", 0);
        }
    }
受保护的void btnUploadDocument(对象发送方,事件参数e)
{
尝试
{
字符串PathToSave=“”;
字符串FolderLocation=“”;
字符串FileName=“”;
字符串pathtob=“”;
字符串FileType=“”;
如果(!DocumentFileUpload.HasFile)
{
DocumentFileUpload.Focus();
lblUploadMsg.Visible=true;
lblUploadMsg.Text=“选择文件名。”;
lblUploadMsg.Focus();
lblUploadMsg.CssClass=“FailedAlert”;
返回;
}
其他的
{
FileUploaderBO objBO=newfileuploaderbo();
FileUploaderData objdata=新FileUploaderData();
//******用于将图像保存到数据库******//
//int length=DocumentFileUpload.PostedFile.ContentLength;
//字节[]imgbyte=新字节[长度];
//HttpPostedFile img=DocumentFileUpload.PostedFile;
//img.InputStream.Read(imgbyte,0,长度);
//objdata.ByteImage=imgbyte;
//******结束将图像保存到数据库******//
FileType=ddlFileType.SelectedItem.Text;
FolderLocation=Server.MapPath(@“~/FileFolder/”+FileType+“/”);
如果(!Directory.Exists(FolderLocation))
{
CreateDirectory(FolderLocation);
}
PathToSave=Server.MapPath(@“~/FileFolder/”+FileType+“/”);
FileName=DocumentFileUpload.FileName;
PathToDB=“~/FileFolder/”+文件类型+“/”+文件名;
PathToDB=“~/FileFolder/”+文件类型+“/”+文件名;
字符串fileCheck=PathToSave+FileName;
字符串tempFileToCheck=“”;
如果(System.IO.File.Exists)(f