473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Only writing 1 byte to a file stream on one pc in office

Hi,
I read image data from a database and cache them locally to file via a
filestream.
One of my users commented that his application isnt showing images. On
checking his file cache I found that most of the files were only 1 byte in
length. I deleted all the files, re-ran the application and again the files
were truncated after 1 byte.
I protect my code with try/catch and log all exceptions to the windows event
log and to a log file. There were no exceptions listed.
We're on a domain.
The code works fine on other pcs. I can't work out why only one byte, or why
there's no error

// read in the record with binary reader
tableImages datarecord = new tableImages(reader);
// write the image to file
FileStream fs = new FileStream(ImageLocation, FileMode.Create,
FileAccess.Write, FileShare.None);
try
{
// Assign the image bytes to variable
byte[] data = datarecord.FileData;
fs.Write(data, 0, data.Length);
fs.Flush();
}
finally
{
fs.Close();
}// finally

Jul 23 '07 #1
3 1379
In this instance though you are not catching and logging anything. You are
just ignoring any issues and closing the open stream.

"Claire" wrote:
Hi,
I read image data from a database and cache them locally to file via a
filestream.
One of my users commented that his application isnt showing images. On
checking his file cache I found that most of the files were only 1 byte in
length. I deleted all the files, re-ran the application and again the files
were truncated after 1 byte.
I protect my code with try/catch and log all exceptions to the windows event
log and to a log file. There were no exceptions listed.
We're on a domain.
The code works fine on other pcs. I can't work out why only one byte, or why
there's no error

// read in the record with binary reader
tableImages datarecord = new tableImages(reader);
// write the image to file
FileStream fs = new FileStream(ImageLocation, FileMode.Create,
FileAccess.Write, FileShare.None);
try
{
// Assign the image bytes to variable
byte[] data = datarecord.FileData;
fs.Write(data, 0, data.Length);
fs.Flush();
}
finally
{
fs.Close();
}// finally

Jul 23 '07 #2
On Mon, 23 Jul 2007 03:49:19 -0700, Claire <cc@nospam.comwrote:
[...]
One of my users commented that his application isnt showing images. On
checking his file cache I found that most of the files were only 1 byte
in
length. I deleted all the files, re-ran the application and again the
files
were truncated after 1 byte.
Well, the code you posted doesn't seem to have any obvious problems. So,
clearly you haven't posted all of the interesting code. For example, what
does the tableImages.FileData property do?

I prefer the "using" syntax rather than a try/catch/finally without a
catch...seems "nicer" to me. But I don't think that should affect your
issue.

I would say that either the data length in your scenario is actually 1
byte, or something is going wrong when you write it. You should debug the
code to get more information about what is actually happening. Also,
maybe you should check the FileStream.Position property to see just how
many bytes were really written.

If you want more help from here, you should post a concise-but-complete
sample of code that reliably reproduces the problem. Don't post more code
than is minimally required to reproduce the problem.

It's likely you'll find the error simply by creating the sample, but if
not then at least you'll have something you can post here and which others
can practically use to try to help you with the problem.

Pete
Jul 23 '07 #3

"ModelBuilder" <Mo**********@discussions.microsoft.comwrote in message
news:E5**********************************@microsof t.com...
In this instance though you are not catching and logging anything. You
are
just ignoring any issues and closing the open stream.
???

The OP has a finally block, not catch (...), so he isn't ignoring anything.
His application-level exception handler will log any exception... but the
whole call stack should be checked for silent discards.
>
"Claire" wrote:
>Hi,
I read image data from a database and cache them locally to file via a
filestream.
One of my users commented that his application isnt showing images. On
checking his file cache I found that most of the files were only 1 byte
in
length. I deleted all the files, re-ran the application and again the
files
were truncated after 1 byte.
I protect my code with try/catch and log all exceptions to the windows
event
log and to a log file. There were no exceptions listed.
We're on a domain.
The code works fine on other pcs. I can't work out why only one byte, or
why
there's no error

// read in the record with binary reader
tableImages datarecord = new tableImages(reader);
// write the image to file
FileStream fs = new FileStream(ImageLocation, FileMode.Create,
FileAccess.Write, FileShare.None);
try
{
// Assign the image bytes to variable
byte[] data = datarecord.FileData;
fs.Write(data, 0, data.Length);
fs.Flush();
}
finally
{
fs.Close();
}// finally


Jul 23 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Weir | last post by:
I'm sure this is a very simple thing to do, once you know how to do it, but I am having no fun at all trying to write utf-8 strings to a unicode file. Does anyone have a couple of lines of code...
5
by: Mike Murray | last post by:
Hi I have the following issue. I have a character that is return by a SQL Server database "É" to be precise, the issue is that when I store character in a .net string variable my understanding...
16
by: Ali | last post by:
Hi I want to write (or read) to a stream, but the data is not byte array I converted the data to byte array manually, but it is very slow, (becuse the data is very large) Is another way for this...
4
by: Scott, Killer of all Ninjas | last post by:
It seems incredulous to me that it is so difficult to write the contents of a memory stream to a file. I'm certain that I'm missing something simple. I am retrieving a memory stream from a DIME...
2
by: Lars Netzel | last post by:
Here's what I need to do: Due to a bug in Crystal Reports ExportToStream() method I can't stream a Crystal Reports directly to the client as PDF and I must must use the Export() and put the the...
7
by: W. Jordan | last post by:
Hello, I am using Response.WriteFile (filename) to write a file that on the server to my web client. I discover that the while a client request a big file, for example, a 14m-bytes one, the...
35
by: RyanS09 | last post by:
Hello- I am trying to write a snippet which will open a text file with an integer on each line. I would like to read the last integer in the file. I am currently using: file = fopen("f.txt",...
8
by: Thirsty Traveler | last post by:
I have a dataset that is returned from a sql server select that contains metadata and a cached dataset saved in an xml column. I would like to recover the dataset for use in generating a crystal...
16
by: billsahiker | last post by:
I am researching for an upcoming c# .net 2.0 project that may require reading and writing xml files. I don't want to use xmltextreader/ xmltextwriter as I prefer to have lower level file access...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.