-
-
Stream st;
-
FileStream f = new FileStream(@"D:\samp\rt.jpg", FileMode.Create);
-
byte[] b = new byte[10000];
-
-
st.Read(b, 0, b.Length);
-
-
st.Close();
-
f.Write(b, 0, b.Length);
-
f.Flush();
-
f.Close();
-
i doesn't show error.
but it gets noting stored.why?
but other files would be saved.but incase of image file,its happening thus.
12 41099 -
Stream st=fromsomesource;
-
FileStream f = new FileStream(@"D:\samp\rt.jpg", FileMode.Create);
-
byte[] b = new byte[10000];
-
st.Read(b, 0, b.Length);
-
st.Close();
-
f.Write(b, 0, b.Length);
-
f.Flush();
-
f.Close();
i doesn't show error.
but it gets noting stored.why?
but other files would be saved.but incase of image file,its happening thus.
PRR 750
Expert 512MB FileStream Read -
//Read image file
-
byte[] b = null;
-
using (FileStream f = new FileStream(@"C:\Bernese Oberland.jpg", FileMode.Open))
-
{
-
b = new byte[f.Length];
-
-
f.Read(b, 0, b.Length);
-
}
-
-
// Write to file ...
-
using (FileStream fs = new FileStream(@"C:\Bernese Oberland1.jpg", FileMode.Create))
-
{
-
fs.Write(b, 0, b.Length);
-
-
}
-
No. stream is coming from webresponse.getStream() method.
so i need a solution for that one.
Well, there's probably an easier way, but if you wanted you could use the ReadByte method of the stream and add each byte you read to a System.Collectiosn.Generic.List<byte> until the byte you read is -1 (end of stream) and then convert the List into a byte[].
Lots of ways to do it though.
@insertAlias
but image does not get stored.should i follow something like sequential access?
PRR 750
Expert 512MB
Could you post more sample code? and maybe flow of your program...
@DeepBlue -
ArrayList addrs = new ArrayList();
-
//addrs.Add("http://iis02.northcomp.com");
-
//addrs.Add("http://iis03.northcomp.com");
-
//addrs.Add("http://ncs01.northcomp.com");
-
addrs.Add("http://c4.mobimgs.com/swarea/assets/ad56e59c/164446_scr.gif");
-
foreach (string s in addrs)
-
{
-
try
-
{
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s);
-
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
-
//HttpResponse rd = new HttpResponse();
-
-
Stream st = resp.GetResponseStream();
-
FileStream f = new FileStream(@"f:\pic\samp\rt.jpg", FileMode.Create);
-
byte[] b = new byte[10000];
-
-
st.Read(b, 0, b.Length);
-
-
st.Close();
-
f.Write(b, 0, b.Length);
-
f.Flush();
-
f.Close();
-
//StreamReader sr = new StreamReader(st);
-
-
//string buffer = sr.ReadToEnd();
-
//int startPos, endPos;
-
//startPos = buffer.IndexOf("<title>",
-
// StringComparison.CurrentCultureIgnoreCase) + 7;
-
//endPos = buffer.IndexOf("</title>",
-
// StringComparison.CurrentCultureIgnoreCase);
-
//string title = buffer.Substring(startPos, endPos - startPos);
-
-
//Console.WriteLine("Response code from {0}: {1}", s,
-
// resp.StatusCode);
-
//Console.WriteLine("Page title: {0}", title);
-
//sr.Close();
-
//st.Close();
-
}
-
catch (Exception ex)
-
{
-
System.Windows.Forms.MessageBox.Show("Error connecting to " + s + "\nException:" + ex.ToString());
-
}
-
}
-
System.Windows.Forms.MessageBox.Show("Web site check completed");
-
-
Give me a solution,i don't want to waste my time though my name is wastman.
- string s="http://c4.mobimgs.com/swarea/assets/ad56e59c/164446_scr.gif";
-
try
-
{
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s);
-
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
-
Stream st = resp.GetResponseStream();
-
FileStream f = new FileStream(@"f:\pic\samp\rt.jpg", FileMode.Create);
-
-
byte[] b = new byte[10000];
-
st.Read(b, 0, b.Length);
-
st.Close();
-
-
f.Write(b, 0, b.Length);
-
f.Flush();
-
f.Close();
-
}
-
catch (Exception ex)
-
{
-
System.Windows.Forms.MessageBox.Show("Error connecting to " + s + "\nException:" + ex.ToString());
-
}
-
-
System.Windows.Forms.MessageBox.Show("Web site check completed");
-
-
Please get me out of a minor mistake which might be.
PRR 750
Expert 512MB
Try this -
public static void Image()
-
{
-
ArrayList addrs = new ArrayList();
-
-
-
//addrs.Add("http://iis02.northcomp.com");
-
//addrs.Add("http://iis03.northcomp.com");
-
//addrs.Add("http://ncs01.northcomp.com");
-
addrs.Add("http://images.devshed.com/af/stories/C_Sharp_Filestream/4.jpg");//http://c4.mobimgs.com/swarea/assets/ad56e59c/164446_scr.gif");
-
foreach (string s in addrs)
-
{
-
try
-
{
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s);
-
//req.ContentType = "image/gif";
-
-
-
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
-
long l = resp.ContentLength;
-
byte[] b = new byte[l];
-
-
-
using (Stream st = resp.GetResponseStream())
-
{
-
using (FileStream f = new FileStream(@"C:\one.jpg", FileMode.OpenOrCreate))
-
{
-
//long len = resp.ContentLength;
-
-
-
st.Read(b, 0, b.Length);
-
-
st.Close();
-
f.Write(b, 0, b.Length);
-
f.Flush();
-
f.Close();
-
}
-
-
}
-
//StreamReader sr = new StreamReader(st);
-
-
//string buffer = sr.ReadToEnd();
-
//int startPos, endPos;
-
//startPos = buffer.IndexOf("<title>",
-
// StringComparison.CurrentCultureIgnoreCase) + 7;
-
//endPos = buffer.IndexOf("</title>",
-
// StringComparison.CurrentCultureIgnoreCase);
-
//string title = buffer.Substring(startPos, endPos - startPos);
-
-
//Console.WriteLine("Response code from {0}: {1}", s,
-
// resp.StatusCode);
-
//Console.WriteLine("Page title: {0}", title);
-
//sr.Close();
-
//st.Close();
-
}
-
catch (Exception ex)
-
{
-
System.Windows.Forms.MessageBox.Show("Error connecting to " + s + "\nException:" + ex.ToString());
-
}
-
}
-
System.Windows.Forms.MessageBox.Show("Web site check completed");
-
-
-
}
-
#endregion
-
No.
The Actual Image:
but the output image:
so that i have got to guess if i have to check some thing like sequential access.
Please help me.
PRR 750
Expert 512MB
use this function -
ArrayList addrs = new ArrayList();
-
-
addrs.Add("http://www.charlespetzold.com/key/keycs.jpg");
-
addrs.Add("http://www.nbcindia.com/Booksimages/1931841306.gif");
-
-
-
int j = 0;
-
foreach (string s in addrs)
-
{
-
try
-
{
-
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(s);
-
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
-
-
using (Stream st = resp.GetResponseStream())
-
{
-
MemoryStream ms =(MemoryStream) CopyStream(st);
-
long len = ms.Length;
-
byte[] b = new byte[len];
-
-
//using (FileStream f = new FileStream(@"C:\one"+j+".jpg", //FileMode.OpenOrCreate))
-
{
-
++j;
-
//long len = resp.ContentLength;
-
-
using (Image image = Image.FromStream(ms))
-
{
-
//st.Read(b, 0, b.Length);
-
-
image.Save(@"C:\one" + j + ".jpg");
-
}
-
}
-
}
-
-
-
// Author Jon Skeet
-
private static Stream CopyStream(Stream inputStream)
-
{
-
const int readSize = 256;
-
byte[] buffer = new byte[readSize];
-
MemoryStream ms = new MemoryStream();
-
int count = inputStream.Read(buffer, 0, readSize);
-
while (count > 0)
-
{
-
ms.Write(buffer, 0, count);
-
count = inputStream.Read(buffer, 0, readSize);
-
}
-
ms.Seek(0, SeekOrigin.Begin);
-
return ms;
-
}
-
I tried with 5-6 images ... almost all are "completely" saved ....
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kevin |
last post by:
Hi all,
Assuming I have stored the binary data of an image file in a blob field
of a table, how can I display it as an image in a web page? I found some
instructions on the web, such as
...
|
by: Umesh |
last post by:
Hi,
I have an Application, in which
1) need to post data to a URL(Remote Server), by using HTTPRequest.
2) get the Image data in the form of Stream in Response.
3) need to save this stream as a...
|
by: andrewcw |
last post by:
Missing the obvious here..thanks..
I need to open the file exclusively for on entry like this:
FileStream stream = null;
stream = File.Open(fiPath, FileMode.Open,...
|
by: a |
last post by:
Save text file as html kloepper 17:42 23 Jul '04
I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html...
|
by: David W. Simmonds |
last post by:
Is there a way I can have a button on a ASP.NET form that when clicked will
allow the user to save the image to a file on the client side? I know that
the user can simply rclick the image and...
|
by: moondaddy |
last post by:
Using vb.net I need to download image files to the client browser where they
can save to disk. Below is some sample code I'm using. when I run this the
File Download window in the browser says:
...
|
by: http://www.visual-basic-data-mining.net/forum |
last post by:
I have a page where it requires user to upload an image file to the server.
For the uploading, i am using HTML imput file control.
Is there a way where after the user has selected a picture file,...
|
by: hnpatel |
last post by:
hello friends,
i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application.
Now I want to save image file in sql database. i m using blob datatype of image field. i...
|
by: premprakashbhati |
last post by:
hi, good evening..
i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button()
here is the code ...its work fine...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |