Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.....
JavaScript
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;


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

1 solution

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
 
Share this answer
 
Comments

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900