繁体   English   中英

使用HTML和ASP.NET Web服务上传文件

[英]File upload using HTML and asp.net web service

我要上传文件,通常是excel或word文件。 设计就像我有一个具有文件上传控制权的html页面,该页面托管在服务器中

上载文件时,它将在asp.net中调用Web服务以将数据插入数据库。这被视为单独托管在同一服务器上的单独应用程序。 数据事务通过JSON进行。

但是我无法获取该文件,所有其他数据均已清除,并将其插入到DB中。

任何人都可以帮助我解决这个问题吗?

样例代码

   $(function () {
   //add document button click
       $("#btn_AddDoc").click( function (e) {
          e.preventDefault();
          var InsDocDet = {};
          InsDocDet.docname=$("#ipDocId").val();

          InsDocDet.ownerUser=1;
          InsDocDet.catid=$("#drp_cat").val();
          InsDocDet.createDatetime=new Date();
          InsDocDet.description_d=$("#doc_desc").val();
          InsDocDet.comments_=$("#doc_cmnt").val();
          InsDocDet.deptid_=$("#Drp_dept").val();
          InsDocDet.con_type=1;
          InsDocDet.size_=1;
          InsDocDet.Doc_status="up";
          var fullPath =$("#Upload_doc").val(); //document.getElementById('doc_upload').value;
          if (fullPath) {
              var startIndex = (fullPath.indexOf('\\') >= 0 ? fullPath.lastIndexOf('\\') : fullPath.lastIndexOf('/'));
              var filename = fullPath.substring(startIndex);
              if (filename.indexOf('\\') === 0 || filename.indexOf('/') === 0) {
              filename = filename.substring(1);
                    InsDocDet.file_name=filename;
                }
          }
          $.ajax({
              type: "POST",
              url: "http://localhost/Service/Service.asmx/srv_Insert_Document",
              data: "{ins_Doc:" + JSON.stringify(InsDocDet) + "}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (r) {           
                        console.log("RT");
              }
          });
      });
     //add document--- 

  });

问候,

西瓦吉斯(Sivajith S.)

如果仅在服务器上发生这种情况,请检查您是否对保存文件的特定目录具有适当的读/右权限,还请检查文件状态是否不受读保护(或它的资源是否可用),这个想法:)),然后尝试访问文件#Alok Sharma

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM