Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9095757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:41:08+00:00 2026-06-16T23:41:08+00:00

I am trying to save Image at server by callback method when I try

  • 0

I am trying to save Image at server by callback method when I try to execute code I get exception Demo Code Example: http://catalog.codeproject.com/Articles/17193/Upload-Images-Using-C-JavaScript-and-ASP-NET-2-0-C

Stream s = File.OpenRead(returnValue); in cs file I m geting exception File Not Found

  <input id="File1" runat="server"  onchange="PopulateList(this)" name="File1" type="File" />

<script language="javascript" type="text/javascript">

    var counter = 1;
    var newPath = '';
    var filePath = '';


    function PopulateList(obj) {
        // Upload the image to the server folder 
        filePath = obj.value;
        // calls the server's method using client callbacks    
        CallServer(obj.value, '');
    }

    function ReceiveServerData(rValue) {

        // The new path will contain the path of the image which is inside the server's folder 
        newPath = rValue;
        alert(newPath);
        //CreateNestedElements();

    }
</script>

In Cs File

protected string returnValue = String.Empty;

protected void Page_Load(object sender, EventArgs e)
{
    string[] filePaths = null;

    //HtmlInputHidden hiddenControl = (HtmlInputHidden)Page.FindControl("list");
    //if (!String.IsNullOrEmpty(hiddenControl.Value))
    //{
    //    filePaths = hiddenControl.Value.Split('|');

    //    //SaveFilesToDB(filePaths);

    //}

    // register the callback script 

    string sbReference = ClientScript.GetCallbackEventReference(this, "arg", "ReceiveServerData", "context");

    string cbScript = String.Empty;

    // check if the script is already registered or not 

    if (!ClientScript.IsClientScriptBlockRegistered("CallServer"))
    {

        cbScript = @" function CallServer(arg,context) { " + sbReference + "}";

        ClientScript.RegisterClientScriptBlock(this.GetType(), "CallServer", cbScript, true);

    }
}


public string GetCallbackResult()
{
    string fileName = System.IO.Path.GetFileName(returnValue);

    string path = Server.MapPath("Images/");
    string fullPath = path + fileName;

    Stream s = File.OpenRead(returnValue);

    byte[] buffer = new byte[s.Length];
    s.Read(buffer, 0, (int)s.Length);

    int len = (int)s.Length;

    s.Dispose();
    s.Close();

    FileStream fs = new FileStream(fullPath, FileMode.Create);
    fs.Write(buffer, 0, len);

    Bitmap bmp = new Bitmap(fs);


    if (System.IO.Path.GetExtension(returnValue).Equals(".gif"))
    {
        bmp.Save(fs, ImageFormat.Gif);
    }
    else
    {
        bmp.Save(fs, ImageFormat.Jpeg);
    }

    bmp.Dispose();

    fs.Dispose();
    fs.Close();                      

    return "Images/" + fileName;
}

public void RaiseCallbackEvent(string eventArgument)
{
    if (!String.IsNullOrEmpty(eventArgument))
    {
        returnValue = eventArgument;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:41:09+00:00Added an answer on June 16, 2026 at 11:41 pm

    Unfortunately, the code-project article that you have linked is utterly rubbish – the code will work only if you are using the same machine as client and server and that too only in internet explorer. In other cases, you are bound to get an exception because the the file path that has been sent to server would be local file path on client machine and will not be present on the server machine (causing File.OpenRead to fail as path is invalid on server).

    I am not sure exactly as what you want to achieve – you will find plenty of plugins or sample if you want to upload file asynchronously. For example, you may use AJAX toolkit AsyncFileUpload control.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
I am trying to save image to database with Create method. but when try
Trying to save an image url for example http://ecx.images-amazon.com/images/I/51d2Qu4RGFL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA300_SH20_OU01_.jpg My Migration: t.string promo_url My
I am trying to save multiple image using this code. But instead its saving
I'm trying to get an image from URL and save it to the isolated
Here's what I'm trying to accomplish: Load an image from a remote server Save
I'm trying to save canvas as a image file ,users get to determine which
I'm trying to save image into sql-server using linq. I set the field type
I'm trying to grab the image located here and save it in my server
Trying to save image to my server using cURL. The image appears to download.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.