从jquery到codebehind时,fileupload postedfile为null. [英] fileupload postedfile is null when getting from jquery to codebehind.

查看:76
本文介绍了从jquery到codebehind时,fileupload postedfile为null.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好Iam yogesh sharma iam在从HTML输入文件中保存发布文件时遇到问题
放入某个文件夹...
我必须使用jquery获取html输入文件的PostFile,然后使用webmethod将其从后台代码保存到某个文件夹中.我的问题是,当我检查
通过调试我在webmethod中的文件,我将发布文件设为NULL.我得到的是该文件的大小,可以.但是postfile为null..
我的Jquery代码是.....

Hi Iam yogesh sharma iam having problems in saving the postedfile from HTML input file
into some folder...
I Have to get the PostedFile of html input file using jquery and save that file into some folder from codebehind using webmethod. my problem is that when i checked the
file in webmethod by debugging i get the postedfile as NULL. I am getting the size of that file which is OK.But postedfile is null..
My Jquery Code Is.....

function SubmitImage_Click() {
                   var postedfile = ($("#fupdImg"))[0].files[0];
                   //alert(postedfile);
                   var exist = $("#fupdImg").val().split('.').pop();
                   PageMethods.GetNewImageName(exist, postedfile);                     
And My Code behind is....
<pre lang="c#">
[System.Web.Services.WebMethod()]
    [System.Web.Script.Services.ScriptMethod()]
    public static void GetNewImageName(string extension,HtmlInputFile file)
    {
        clsMNC obj = new clsMNC();
        string ssql = "select Count(ProductId)+1 from Product";
        Int32 pid = Convert.ToInt32(obj.getOneValue(ssql));
        string imgName = "img" + "_" + pid +"."+ extension;
        //return imgName;
        string savepath = HttpContext.Current.Server.MapPath(".") + "\\UserImgs\\";
        savepath += imgName;
        hp=file.PostedFile;



在这里我想使用SaveAs方法保存file.postedfile ...
请帮忙,我正在尝试2天以来,但没有收到google的答复.
任何帮助将不胜感激...



Here I want to save file.postedfile using SaveAs Method...
Please help, I am Trying Since 2 days but not getting answer from google..
Any Help wiil be appreciated...

推荐答案

(" #fupdImg"))[ 0 ]; // alert(postedfile); var 存在=
("#fupdImg"))[0].files[0]; //alert(postedfile); var exist =


(" ).val().split(' .' ).流行音乐(); PageMethods.GetNewImageName(exist,postfile); 而我背后的代码是... < pre lang = " > [System.Web.Services.WebMethod()] [System.Web.Script.Services.ScriptMethod()] 公共 静态 void GetNewImageName(字符串扩展名, HtmlInputFile文件) { clsMNC obj = clsMNC(); 字符串ssql = " ; Int32 pid = Convert.ToInt32(obj.getOneValue(ssql)); 字符串imgName = " + " _" + pid + ." +扩展名; // 返回imgName; 字符串savepath = HttpContext.Current.Server.MapPath(" )+ \\ UserImgs \\"; savepath + = imgName; hp = file.PostedFile;
("#fupdImg").val().split('.').pop(); PageMethods.GetNewImageName(exist, postedfile); And My Code behind is.... <pre lang="c#"> [System.Web.Services.WebMethod()] [System.Web.Script.Services.ScriptMethod()] public static void GetNewImageName(string extension,HtmlInputFile file) { clsMNC obj = new clsMNC(); string ssql = "select Count(ProductId)+1 from Product"; Int32 pid = Convert.ToInt32(obj.getOneValue(ssql)); string imgName = "img" + "_" + pid +"."+ extension; //return imgName; string savepath = HttpContext.Current.Server.MapPath(".") + "\\UserImgs\\"; savepath += imgName; hp=file.PostedFile;



在这里我想使用SaveAs方法保存file.postedfile ...
请帮忙,我正在尝试2天以来,但没有收到google的答复.
任何帮助将不胜感激...



Here I want to save file.postedfile using SaveAs Method...
Please help, I am Trying Since 2 days but not getting answer from google..
Any Help wiil be appreciated...


无论何时发生回发,posted-file属性都将变为空白,因此人们可以通过许多方式来处理文件控制,例如
您可以在文件上传控件附近放置一个按钮(例如Upload),现在用户将选择文件并单击按钮上传,在上传按钮的click事件上,您可以将post-file属性设置为某个隐藏字段,一旦用户单击在页面上的最终提交按钮上,然后您可以将文件上传到服务器.

尝试 [ ^ ].



--Amit
Whenever post-back occurs, the posted-file property becomes blank, so people handle file control in many ways like

you can place a button (say Upload) near to file upload control, now user will select file and hit the button upload, on the click event of the upload button u can set the posted-file property to some hidden field, once user click on final submit button on the page, then u can upload the file to server.

Try this[^].



--Amit


这篇关于从jquery到codebehind时,fileupload postedfile为null.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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