Hi
Probability of this phenomena is like 1/200.
The only code where I am dealing with file is the following:
using (FileStream fs = new FileStream(this .FilePath,
FileMode.Open,F ileAccess.Read) )
{
try
{
// This is web service call to check if i user has
permissions to upload file
myObj.BeforeUpl oad(this.FileNa me,
this.ServerPath );
while ((this.Offset < this.FileSize) && !
this.Stop)
{
fs.Seek(Offset, SeekOrigin.Begi n);
buffer = new byte[32 * 1024];
BytesRead = fs.Read(buffer, 0, buffer.Length);
byte[] buff = new byte[BytesRead];
Copy(buffer, 0, buff, 0, BytesRead);
myObj.UploadChu nk(this.FileNam e,
this.ServerPath , this.Offset, buff);
this.Offset += buff.Length;
//report progress to backgroundworke r
bgw.ReportProgr ess((int)(((dec imal)Offset /
(decimal)FileSi ze) * 100));
}
}
finally
{
fs.Close();
}
}
Question is. Why sometimes such an operation leaves my file empty.
This is upload file code. I have left every line unchanged. If you
have more skills than me try to explain this phenomena because I have
no more ideas.
Regards
ps:( I would be really grateful for an explanation )
Piotr Kolodziej 7 1942
Your code cannot truncate the file, unless there is a nice big bug in the
FileStream, but I doubt it.
So the file truncation must come from somewhere else, maybe a sharing or
race condition.
If you change the to
using(FileStrea m fs=new
FileStream(this .FilePath,FileM ode.Open,FileAc cess.Read,FileS hare.None))
In this way you deny any sharing of the file so no one can truncate it..
unless some fs filter kicks in (like virus scanners).
But this is just a huge guess.
"Piotrekk" <Pi************ *@gmail.comha scritto nel messaggio
news:11******** *************@1 9g2000hsx.googl egroups.com...
Hi
Probability of this phenomena is like 1/200.
The only code where I am dealing with file is the following:
using (FileStream fs = new FileStream(this .FilePath,
FileMode.Open,F ileAccess.Read) )
{
try
{
// This is web service call to check if i user has
permissions to upload file
myObj.BeforeUpl oad(this.FileNa me,
this.ServerPath );
while ((this.Offset < this.FileSize) && !
this.Stop)
{
fs.Seek(Offset, SeekOrigin.Begi n);
buffer = new byte[32 * 1024];
BytesRead = fs.Read(buffer, 0, buffer.Length);
byte[] buff = new byte[BytesRead];
Copy(buffer, 0, buff, 0, BytesRead);
myObj.UploadChu nk(this.FileNam e,
this.ServerPath , this.Offset, buff);
this.Offset += buff.Length;
//report progress to backgroundworke r
bgw.ReportProgr ess((int)(((dec imal)Offset /
(decimal)FileSi ze) * 100));
}
}
finally
{
fs.Close();
}
}
Question is. Why sometimes such an operation leaves my file empty.
This is upload file code. I have left every line unchanged. If you
have more skills than me try to explain this phenomena because I have
no more ideas.
Regards
ps:( I would be really grateful for an explanation )
Piotr Kolodziej
Your code cannot truncate the file, unless there is a nice big bug in the
FileStream, but I doubt it.
So the file truncation must come from somewhere else, maybe a sharing or
race condition.
If you change the to
using(FileStrea m fs=new
FileStream(this .FilePath,FileM ode.Open,FileAc cess.Read,FileS hare.None))
In this way you deny any sharing of the file so no one can truncate it..
unless some fs filter kicks in (like virus scanners).
But this is just a huge guess.
Thanks for your post. I forgot to say that this weird truncation
happens when I am uploading the same file many times one by one ( to
test reaction of SQL - which is noticing the reception ). I did it for
example 20 times, in one minute, and when i attempt to do it again I
see ( in openFileDialog ) that file is truncated. What do you think
about 'sharing' or 'race condition' now? I know what race condition is
but I have never been thinking about this in file categories.
"Piotrekk" <Pi************ *@gmail.comwrot e in message
news:11******** **************@ r29g2000hsg.goo glegroups.com.. .
>
>Your code cannot truncate the file, unless there is a nice big bug in the FileStream, but I doubt it. So the file truncation must come from somewhere else, maybe a sharing or race condition. If you change the to
using(FileStre am fs=new FileStream(thi s.FilePath,File Mode.Open,FileA ccess.Read,File Share.None))
In this way you deny any sharing of the file so no one can truncate it.. unless some fs filter kicks in (like virus scanners).
But this is just a huge guess.
Thanks for your post. I forgot to say that this weird truncation
happens when I am uploading the same file many times one by one ( to
test reaction of SQL - which is noticing the reception ). I did it for
example 20 times, in one minute, and when i attempt to do it again I
see ( in openFileDialog ) that file is truncated. What do you think
about 'sharing' or 'race condition' now? I know what race condition is
but I have never been thinking about this in file categories.
In any case it isn't the code you've shown, because you open the file
read-only. You're either opening the file somewhere else, or you have disk
corruption and possible hardware failure.
In any case it isn't the code you've shown, because you open the file
read-only. You're either opening the file somewhere else, or you have disk
corruption and possible hardware failure.
Is that possible that the same code is trying to open this file while
the previous thread ( the same code ) hasn't finished with it yet?
This phenomena happens only when I upload the same file saveral times
in a row. Maybe OS is doing something with the opened and closed file
and another upload
form is trying to read it?
No disk corruption occured since this happens also on my new computer.
"Piotrekk" <Pi************ *@gmail.comwrot e in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
>
>In any case it isn't the code you've shown, because you open the file read-only. You're either opening the file somewhere else, or you have disk corruption and possible hardware failure.
Is that possible that the same code is trying to open this file while
the previous thread ( the same code ) hasn't finished with it yet?
This phenomena happens only when I upload the same file saveral times
in a row. Maybe OS is doing something with the opened and closed file
and another upload
form is trying to read it?
No disk corruption occured since this happens also on my new computer.
Are you catching any exceptions?
On 9 Pa , 16:53, "Ben Voigt [C++ MVP]" <r...@nospam.no spamwrote:
"Piotrekk" <Piotr.Kolodz.. .@gmail.comwrot e in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
In any case it isn't the code you've shown, because you open the file
read-only. You're either opening the file somewhere else, or you have
disk
corruption and possible hardware failure.
Is that possible that the same code is trying to open this file while
the previous thread ( the same code ) hasn't finished with it yet?
This phenomena happens only when I upload the same file saveral times
in a row. Maybe OS is doing something with the opened and closed file
and another upload
form is trying to read it?
No disk corruption occured since this happens also on my new computer.
Are you catching any exceptions?
Nope. No exceptions at all. Everything seems to work fine. Files are
uploaded. When I only experiment with one file ( upload ) too
much ...this happens.
Are you catching any exceptions?
Nope. No exceptions at all. Everything seems to work fine. Files are
uploaded. When I only experiment with one file ( upload ) too
much ...this happens.
UploadForm code is available here for those of You who might want to
look at the complete code. It's not long thus it makes it hard to find
such a bug. http://mion.elka.pw.edu.pl/~pkolodzi/UploadForm.cs
Regards
Piotr Kolodziej This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Viorel |
last post by:
About FileStream and StreamWriter!?
I have a string1 which contains(of course in unicode) a html code with
Unicode charset specified in it.
1)
bytecontent= System.Text.UnicodeEncoding.Unicode.GetBytes(string1);
|
by: Dorsa |
last post by:
HI, Could you please tell me the error in here. I am trying to open an
XML file from a link.
Response.Clear()
Response.Expires = 0
Response.BufferOutput = False
Response.ContentType = "text/xml"
Response.AddHeader("Content-Disposition",
"filename=test.XML")
|
by: Mark Waser |
last post by:
Hi all,
I'm trying to post multipart/form-data to a web page but seem to have
run into a wall. I'm familiar with RFC 1867 and have done this before (with
AOLServer and Tcl) but just can't seem to get it to work in Visual Basic. I
tried coding it once myself from scratch and then modified a class that I
found on a newsgroup (referenced...
|
by: ljlevend |
last post by:
I have two questions related to FileStreams.
1. Is there any way to determine whether a file has the permissions that are
required by a FileStream constructor? For example, given the following
sample:
Dim fs1 As New System.IO.FileStream("C:\Test.txt", IO.FileMode.OpenOrCreate,
IO.FileAccess.ReadWrite, IO.FileShare.Read)
'...
'This is...
|
by: JDeats |
last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting
and decrypting a file.
http://support.microsoft.com/kb/307010
In .NET 2.0 this approach is not fully supported (a .NET 2.0 build
with these methods, will appear to encrypt and decrypt, but the
resulting decrypted file will be corrupted. I tried encrypting a .bmp
file and...
| |
by: WeCi2i |
last post by:
Okay, I have a problem that has been stumping me for weeks. I have tried many different solutions and this is pretty much my last resort. I have seen a lot of good answers give here so I figured I would give it a try.
First of all, I am using Visual Studio 2005 to write my program. I am using C# .NET as the language. I am running Windows XP...
|
by: shlim |
last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with "The remote server returned an error: (500) Internal Server Error". Obviously, this means that I have not posted all the parameters as the servlet...
|
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= |
last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is
streamed from handler in ASP.net" at
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.aspnet&mid=e9a38d03-83a8-41fc-8950-5ee60d2a18a5.
I have a web site under .NET 2.0 that renders videos using the Silverlight...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |