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

  • Home
  • SEARCH
  • 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 326087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:16:37+00:00 2026-05-12T09:16:37+00:00

I have the following object: [Serializable] public class ExampleImage { public int ID {

  • 0

I have the following object:

[Serializable]
public class ExampleImage
{
    public int ID { get; set; }
    public string Filename { get; set; }
    public byte[] Content { get; set; }
}

I store this in a List<ExampleImage> which I then pass to the following function to serialize it to a string:

static string SerializeObjectToXmlString(object o)
{
    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(o.GetType());
    System.IO.StringWriter writer = new System.IO.StringWriter();
    serializer.Serialize(writer, o);
    return writer.ToString();
}

I then pass this serialized string to a stored procedure in SQL2000 as an NTEXT which then handled for inserting it into the database:

SELECT * INTO #TempImages
FROM OpenXML(@iDoc, '/ArrayOfExampleImage/ExampleImage')
WITH ([Filename] VARCHAR(255) './Filename', [Content] IMAGE './Content')

The problem I am having is the image is getting trashed. The btye[] is not getting saved properly to the DB. The other fields are just fine. This is the first time I have attempt to send a binary data via XML to SQL so I am most likely doing something wrong at this point. Is my SerializeObjectToXmlString function the problem and it is not handling the serialization of a byte[] properly, maybe the OpenXML SQL function or even the fact that I am sending the XML in as an NTEXT param. I would expect the serialize function to encode the binary properly but I could be wrong.

Any idea what is the issue or maybe a better approach to saving a bunch of images at once?

Edit: I think what is happening, is the serializer is making the byte[] into a base64 string, which is then getting passed along to the stored proc as base64. I am then saving this base64 string into an Image field in SQL and reading it out as a btye[]. So I think I need to somehow get it from base64 to a byte[] before inserting it in my table?

Edit: I am starting to think my only option is to change the stored proc to just do 1 image at a time and not use XML and just pass in the byte[] as an Image type and wrap all the calls in a transaction.

  • 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-05-12T09:16:37+00:00Added an answer on May 12, 2026 at 9:16 am

    As Gaidin suggested, base64 is the best option. It’s the usual way of writing binary data to XML. You can use the following code :

    public class ExampleImage
    {
        public int ID { get; set; }
        public string Filename { get; set; }
    
        [XmlIgnore]
        public byte[] Content { get; set; }
    
        [XmlElement("Content")]
        public string ContentBase64
        {
            get { return Convert.ToBase64String(Content); }
            set { Content = Convert.FromBase64String(value); }
        }
    }
    

    (by the way, the Serializable attribute has no meaning for XML serialization)

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

Sidebar

Ask A Question

Stats

  • Questions 210k
  • Answers 210k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This isn't really an answer, but I think you're on… May 12, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer Yes you can do that in some cases. I suggest… May 12, 2026 at 9:59 pm
  • Editorial Team
    Editorial Team added an answer I can't remember if the cookie that ASP.NET sets as… May 12, 2026 at 9:59 pm

Related Questions

I currently use the following approach to create a strongly typed object representing session
When the following class is serialized with a BinaryFormatter , any objects subscribing to
I am developing an asp.net (3.5) application and I am puzzled with the behavior
I'm using the Google App Engine in combination with the Google Web Toolkit to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.