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 761637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:51:42+00:00 2026-05-14T15:51:42+00:00

I am developing a web application that calls web services developed by a third

  • 0

I am developing a web application that calls web services developed by a third party to send/receive data from a clients database. I am building the application using ASP.NET 3.5 C#.

The way that they are providing me images is in BLOB format. I call their method and what I get back is a DataSet with 2 fields “logo_name” and “logo” which is the BLOB field.
What I want to do is: Save the image locally on the disk (to minimize calls to their database in the future).

I have been playing around with a couple of different ways of doing this but cannot seem to get the image to save correctly. I have been able to create a file in a folder with the correct name but if I try to view the image it does not work.

I was hoping someone could give me some sample code to show me how to save a BLOB field to the local disk?

Here is the code I currently have

public static class ProductImages
    {


        public static string GetSchoolLogo(string schoolID, string printCodeID)
        {
            int v_length = 0;
            string v_file_name = "";
            byte[] v_file_data = null;

            try
            {

                //Declare Web Service Variables
                P_SERVICE.Service ldeService = new P_SERVICE.Service();
                //Authentication Header
                ldeService.AuthHeaderValue = CGlobal.GetAuthHeader(System.Web.HttpContext.Current.Session);
                P_SERVICE.CDataResultOfDataSet ldeResult = null;
                DataSet ds = new DataSet();

                ldeResult = ldeService.GetItemLogo(schoolID, printCodeID);
                ds = ldeResult.Value;

                if (ds.Tables[0].Rows.Count > 0)
                {
                    v_file_data = StrToByteArray(ds.Tables[0].Rows[0]["logo"].ToString().TrimEnd());
                    v_file_name = ds.Tables[0].Rows[0]["logo_name"].ToString().TrimEnd();
                    v_length = Convert.ToInt32(v_file_data.Length);

                    // Load the file in the Memory Stream
                    MemoryStream ms = new MemoryStream(v_file_data, 0, v_file_data.Length);
                    ms.Write(v_file_data, 0, v_file_data.Length);

                    // Open the file stream in ordre to save on the local disk
                    string path = HttpContext.Current.Server.MapPath("~/_imagecache/schoolLogos/").ToString();
                    FileStream fs = File.OpenWrite(path + schoolID + "/" + v_file_name);
                    fs.Write(v_file_data, 0, v_file_data.Length);
                    fs.Close();

                    // Return True if no errors occured
                    return "~/_imagecache/schoolLogos/" + schoolID + "/" + v_file_name;
                }
                else
                    return "~/images/noPhoto.gif";

           }

            catch (Exception ex)
            {

                throw new Exception(ex.Message.ToString());
                //return "~/images/noPhoto.gif";
            } 
        }

        // C# to convert a string to a byte array.
        public static byte[] StrToByteArray(string str)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return encoding.GetBytes(str);
        }
    }


}

When I get the Type of data being returned it returns System.String

Type t = ds.Tables[0].Rows[0]["logo"].GetType();
HttpContext.Current.Trace.Warn(t.FullName);

Thanks

  • 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-14T15:51:43+00:00Added an answer on May 14, 2026 at 3:51 pm

    Ok, so it looks like the web service is doing you no favors. They really should be returning a byte array. but anyway, the string is definitely not base64 and definitely not ascii.

    Lets try this wild stab in the dark:

    v_file_data = Encoding.UTF8.GetBytes(ds.Tables[0].Rows[0]["logo"]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would personally put it at the end, in case… May 14, 2026 at 4:47 pm
  • Editorial Team
    Editorial Team added an answer Just return YES no matter what the interface orientation is.… May 14, 2026 at 4:47 pm
  • Editorial Team
    Editorial Team added an answer The important thing to check is the EDMX file and… May 14, 2026 at 4:47 pm

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.