3

I am converting image name to byte array and i want to save that byte array in a folder here is my code to convert byte array

 byte[] imgArray = obj.Image.ToByteArray();

where obj.image=image(1).jpg. which is of string type.

and I want to save it in my project folder "Images" so how can i do it after converting that image file to byte array. please give me some idea to do that

here is my project folder where i want to save the file. D:\Gaurav\VerveLogicTfs\LogoProject\ProfilePic

3
  • 2
    File.WriteAllBytes(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "image1.jpg"), imgArray);? Commented Oct 26, 2017 at 12:43
  • sir your solution is good but i want to save in in this folder @"D:\Gaurav\VerveLogicTfs\LogoProject\ProfilePic Commented Oct 26, 2017 at 12:54
  • "where obj.image=image(1).jpg. which is of string type" - That means obj.Image.ToByteArray() will give you the byte array of that string not the image itself. Commented Oct 26, 2017 at 12:57

1 Answer 1

4

Try this.

string filePath = "~/ProfilePic/" + obj.image.ToString();
File.WriteAllBytes(Server.MapPath(filePath), imgArray);
Sign up to request clarification or add additional context in comments.

Comments

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.