该路径不是合法的表单文件上载ASP.NET [英] The path is not of a legal form file upload ASP.NET

查看:46
本文介绍了该路径不是合法的表单文件上载ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,当我想将文件上传到sql数据库时,它给了我消息

i am facing problem when i want to upload file to sql database it gave me message

The path is not of a legal form. 





我的尝试:





What I have tried:

protected void BtnSaveReply_Click(object sender, EventArgs e)
       {
           FileInfo fi =new  FileInfo(FileUpload1.FileName);
           byte[] Document_Content = FileUpload1.FileBytes;
           string name = fi.Name;
           string Extension = fi.Extension;
           BAL_ObjectsCCRM.BO_Scripts objbo = new BAL_ObjectsCCRM.BO_Scripts();
           objbo.Content_Name = Document_Content;
           objbo.File_Name = name;
           objbo.Extention = Extension;
           Scp.Insert_Script(objbo);


       }





Businness Layer Code



Businness Layer Code

public void Insert_Script(BAL_ObjectsCCRM.BO_Scripts objbo)


       {
           DAL_CCRMUI.DataAccessLayer Dal = new DAL_CCRMUI.DataAccessLayer();
           Dal.Open();
           SqlParameter[] param = new SqlParameter[3];
           param[0] = new SqlParameter("@Content_Name", SqlDbType.NVarChar,200)
           {
               Value = objbo.File_Name
           };
           param[1] = new SqlParameter("@Document_Content", SqlDbType.VarBinary,5000)
           {
               Value = objbo.Content_Name
           };
           param[2] = new SqlParameter("@Extension", SqlDbType.NVarChar,10)
           {
               Value = objbo.Extention

           };

           Dal.ExecuteProcedure("Save_Document", param);
           Dal.Close();

       }



商业对象层




Business objbect Layer

public class BO_Scripts
   {
       public string  File_Name { get; set; }
       public Byte[] Content_Name { get; set; }
       public string  Extention { get; set; }


   }

推荐答案

你不能使用FileInfo,因为服务器上不存在该文件。如果要提取名称和扩展名,请使用System.IO.Path



Path.GetFileName Method(System.IO)| Microsoft Docs [ ^ ]



Path.GetExtension Method(System.IO)| Microsoft Docs [ ^ ]
You can't use FileInfo because the file doesn't exist on the server. If you want to extract the name and extension then use System.IO.Path

Path.GetFileName Method (System.IO) | Microsoft Docs[^]

Path.GetExtension Method (System.IO) | Microsoft Docs[^]


这篇关于该路径不是合法的表单文件上载ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆