Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I was Pulling an image from the path in the format

www.MyImageSite.com/Images/Image1.jpg

And I was using the C# code as follows

C#
HttpWebRequest request = null;
                HttpWebResponse response = null;
                byte[] buff = null;

                string rootDir = GetAppSettingValue(Constants.K_APP_KEY_SC_IMAGE_PATH);
                string fullPath = rootDir + @"/" + fileName+ ".jpg";

                request = (HttpWebRequest)WebRequest.Create(fullPath);
                response = (HttpWebResponse)request.GetResponse();

                if (request.HaveResponse)
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Stream receiveStream = response.GetResponseStream();
                        using (BinaryReader br = new BinaryReader(receiveStream))
                        {
                            buff = br.ReadBytes(500000);
                            br.Close();
                        }
                    }
                }

                return buff;



Here fileName is the argument passing to the function.

But now I have to show the image from the site
MyImageSite.com/Images/[StockCode].jpg (no www.)

Is there any suggestions solutions?
Posted
Updated 3-Nov-14 20:06pm
v2
Comments
Sinisa Hajnal 4-Nov-14 2:08am    
So the code above has nothing to do with your question? What have you tried? What did you find on google?

1 solution

If you just wanted to remove the www. from the string, then why not simply remove it from the initial string?

Stings expose a function where you can replace a string to some other format. Try this,

C#
// create a variable
string url = "www.example.com/images_folder/image_name.png";
// replace with an empty string
string urlWithoutWww = url.Replace("www.", "");


Now you can use the second variable that won't have the initial www. in it to show the image from your own website.

Learn more on String.Replace[^].
 
Share this answer
 
v2
Comments
IpsitaMishra 4-Nov-14 2:34am    
Hi Afzaal Ahmad Zeeshan Thanks for your answer :) .
String.Replace is a very popular function but it will not work for me now :( .
The urlWithoutWww will now look like "example.com/images_folder/image_name.png"
And this is the issue... I am looking for a solution which help me to download the image from the address "example.com/images_folder/image_name.png".
Afzaal Ahmad Zeeshan 4-Nov-14 2:43am    
Then download the image with www and http protocol added. After that, remove that protocol and the www from the string. :)

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