Click here to Skip to main content
15,900,686 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hai all ,

Am getting an error in my function in the place of json. Am i want to include any namespace for that?? Can anyone help me???
public  object ProductImage(string qqfile)
    {

        string imagename = "";
        string filename = "";
        var file = string.Empty;
        try
        {
            var stream = Request.InputStream;
            if (String.IsNullOrEmpty(Request["qqfile"]))
            {
                // IE				
               HttpPostedFileBase postedFile = Request.Files[0];
               stream = postedFile.InputStream;
                imagename =RemoveSpecialChars(DateTime.Now.ToString()) + System.IO.Path.GetFileName(Request.Files[0].FileName);
                filename = System.IO.Path.GetFileName(Request.Files[0].FileName);
                file = Path.Combine(Server.MapPath("~/Uploads"), imagename);
            }
            else
            {
                //Webkit, Mozilla				
                imagename = RemoveSpecialChars(DateTime.Now.ToString()) + qqfile;
                filename = qqfile;
                file = Path.Combine(Server.MapPath("~/Uploads"), imagename);
            }

            var buffer = new byte[stream.Length];
            stream.Read(buffer, 0, buffer.Length);
            System.IO.File.WriteAllBytes(file, buffer);

        }
        catch (Exception ex)
        {
            return Json(new { success = false, message = ex.Message }, "application/json");
        }

        return Json(new { success = true, imagename = imagename, correctname = filename }, "text/html");				



while executing this code am getting an error like this


The name Json does not exist in the current context
Posted
Updated 29-Jul-13 20:08pm
v2
Comments
Ankur\m/ 30-Jul-13 1:03am    
You need to mention "what" error you are getting. Remember we cannot see your machine or read your mind.

You are getting this error because there isn't Json class available in .Net framework and do you don't seem to have created a class with that name in your project or the assemblies you have referenced.

It seems you are trying serialize the data in Json format. Your options are:
i) Just return a string which is in Json format. So you will have to change your return statement to valid Json string (name value pair).
ii) Use a Json library to serialize/de-serialize you string to Json objects. One such library is Json.NET[^]

Hope that helps!
 
Share this answer
 

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