-2

here is my code :

<label for="image" >Image input</label>    
<input id="image" type="file" name="pic" accept="image/*">

i don’t know the code behind to get value from the inserted image and save it in my project folder. please help me. thanks in Advance.

2
  • possible duplicate of Accessing input type file at server side in asp.net Commented Feb 25, 2015 at 5:14
  • hey @artm thankyou for the answer but i dont know why still error on my aspx : <label for="image" >Image input</label> <input id="image" type="file" name="pic" accept="image/*" runat="server"> on my aspx.cs : int contentLength = image.PostedFile.ContentLength; string contentType = image.PostedFile.ContentType; string fileName = image.PostedFile.FileName; image.PostedFile.Save(@"c:\test.tmp"); Commented Feb 25, 2015 at 5:40

1 Answer 1

0

If you want to access what is put into the files collection using jScript:

function SaveImage()
{
    var uploadFileElement = document.getElementById("image");
    var theFile = uploadFileElement.files[0];

    // Use AJAX or call a PageMethod to initiate Server Side Processing
    // to Save the file
}

Just add a standard html button on your form that calls this function to initiate the saving of your file.

If you want to use standard Server Side (ASP.NET Controls), I would suggest using the FileUpload control.

Put this in your aspx page:

<asp:FileUpload ID="FileUpload_UploadFile" runat="server"  />
<asp:Button ID="Button_UploadFile" runat="server" Text="Upload File" onclick="Button_UploadFile_Click" />

Put this in your code behind (.cs):

private void Button_UploadFile_Click(object sender, EventArgs e)
{
    if (FileUpload_UploadFile.HasFile)
    {
        // IMPLEMENT YOUR CODE FOR SAVING THE FILE
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

i still new in this webprog and C# , I 've never touch jScript and AJAX before

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.