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.FileS tream("C:\Test. txt", IO.FileMode.Ope nOrCreate,
IO.FileAccess.R eadWrite, IO.FileShare.Re ad)
'...
'This is allowed.
Dim fs2 As New System.IO.FileS tream("C:\Test. txt", IO.FileMode.Ope nOrCreate,
IO.FileAccess.R ead, IO.FileShare.Re adWrite)
'...
'This raises a System.IO.IOExc eption exception.
Dim fs3 As New System.IO.FileS tream("C:\Test. txt", IO.FileMode.Ope nOrCreate,
IO.FileAccess.R eadWrite, IO.FileShare.Re ad)
Is there any way to test C:\Test.txt for the required permission before fs3
is instantiated (and thus raises an exception)? Note that in general, my app
would not have knowledge of fs1 or fs2 when fs3 is instantiated.
2. Once a FileStream has been created, is there any way to rename the
corresponding file without closing the FileStream? For example, I would like
to do this:
Dim fs As New System.IO.FileS tream("C:\Test. txt", IO.FileMode.Ope nOrCreate,
IO.FileAccess.R eadWrite, IO.FileShare.Re ad)
'...
System.IO.File. Move("C:\Test.t xt", "C:\Test2.t xt")
In this case my app would have knowledge of fs if that helps.
Thanks for any help.
Lance 9 2174
Hi
Comments in line.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
-------------------- Thread-Topic: FileStream questions thread-index: AcTb06DoX9JlGYI fSxObK+HsyPZnQw == X-WBNR-Posting-Host: 68.190.169.55 From: "=?Utf-8?B?bGpsZXZlbmQ =?=" <lj******@nospa m.nospam> Subject: FileStream questions Date: Mon, 6 Dec 2004 12:39:05 -0800 Lines: 34 Message-ID: <49************ *************** *******@microso ft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="Utf-8" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft CDO for Windows 2000 Content-Class: urn:content-classes:message Importance: normal Priority: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 Newsgroups: microsoft.publi c.dotnet.langua ges.vb NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.1.29 Path:
cpmsftngxa10.ph x.gbl!TK2MSFTFE ED02.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGXA 0
3.phx.gblXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:247190 X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
I have two questions related to FileStreams.
1. Is there any way to determine whether a file has the permissions that
arerequired by a FileStream constructor? For example, given the following sample:
Dim fs1 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad) '... 'This is allowed. Dim fs2 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. Read, IO.FileShare.Re adWrite) '... 'This raises a System.IO.IOExc eption exception. Dim fs3 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad)
Is there any way to test C:\Test.txt for the required permission before
fs3is instantiated (and thus raises an exception)? Note that in general, my
appwould not have knowledge of fs1 or fs2 when fs3 is instantiated.
So far we use the try...catch method to detect if we can open the file with
required permission. So if the open operataion will raise exception, we can
catch it and know that the current job will fail.
If the three open operation is under your control, I think you may try use
a third variable to indicate current file's status. So that the other open
user will check to see if we can open the file.
2. Once a FileStream has been created, is there any way to rename the correspondin g file without closing the FileStream? For example, I would
liketo do this:
Dim fs As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad) '... System.IO.File .Move("C:\Test. txt", "C:\Test2.t xt")
In this case my app would have knowledge of fs if that helps.
We can not do that, because once process A is opened the file, the file
will be in open status, the other process(the file move operation) can not
move it, because we need to delete the Test.txt. Can you tell me what is
your scenario? Maybe there is another way. Thanks for any help. Lance
Hi
Comments in line.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
-------------------- Thread-Topic: FileStream questions thread-index: AcTb06DoX9JlGYI fSxObK+HsyPZnQw == X-WBNR-Posting-Host: 68.190.169.55 From: "=?Utf-8?B?bGpsZXZlbmQ =?=" <lj******@nospa m.nospam> Subject: FileStream questions Date: Mon, 6 Dec 2004 12:39:05 -0800 Lines: 34 Message-ID: <49************ *************** *******@microso ft.com> MIME-Version: 1.0 Content-Type: text/plain; charset="Utf-8" Content-Transfer-Encoding: 7bit X-Newsreader: Microsoft CDO for Windows 2000 Content-Class: urn:content-classes:message Importance: normal Priority: normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 Newsgroups: microsoft.publi c.dotnet.langua ges.vb NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.1.29 Path:
cpmsftngxa10.ph x.gbl!TK2MSFTFE ED02.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGXA 0
3.phx.gblXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:247190 X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
I have two questions related to FileStreams.
1. Is there any way to determine whether a file has the permissions that
arerequired by a FileStream constructor? For example, given the following sample:
Dim fs1 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad) '... 'This is allowed. Dim fs2 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. Read, IO.FileShare.Re adWrite) '... 'This raises a System.IO.IOExc eption exception. Dim fs3 As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad)
Is there any way to test C:\Test.txt for the required permission before
fs3is instantiated (and thus raises an exception)? Note that in general, my
appwould not have knowledge of fs1 or fs2 when fs3 is instantiated.
So far we use the try...catch method to detect if we can open the file with
required permission. So if the open operataion will raise exception, we can
catch it and know that the current job will fail.
If the three open operation is under your control, I think you may try use
a third variable to indicate current file's status. So that the other open
user will check to see if we can open the file.
2. Once a FileStream has been created, is there any way to rename the correspondin g file without closing the FileStream? For example, I would
liketo do this:
Dim fs As New System.IO.FileS tream("C:\Test. txt",
IO.FileMode.Ope nOrCreate,IO.FileAccess. ReadWrite, IO.FileShare.Re ad) '... System.IO.File .Move("C:\Test. txt", "C:\Test2.t xt")
In this case my app would have knowledge of fs if that helps.
We can not do that, because once process A is opened the file, the file
will be in open status, the other process(the file move operation) can not
move it, because we need to delete the Test.txt. Can you tell me what is
your scenario? Maybe there is another way. Thanks for any help. Lance
Thanks a lot for the info. I can get along fine with the current
functionality, but I wanted to make sure that there wasn't a better technique.
I do have one more question though. Is there any way to determine if a file
is being used by another application and, if so, the name of that
application? For example, if you open a file in Excel and then attempt to
change the name of the file in Windows Explorer, you get an error message
that includes the name of the application (i.e., Microsoft Office Excel) that
has the file open.
Thanks again,
Lance
Thanks a lot for the info. I can get along fine with the current
functionality, but I wanted to make sure that there wasn't a better technique.
I do have one more question though. Is there any way to determine if a file
is being used by another application and, if so, the name of that
application? For example, if you open a file in Excel and then attempt to
change the name of the file in Windows Explorer, you get an error message
that includes the name of the application (i.e., Microsoft Office Excel) that
has the file open.
Thanks again,
Lance
Hi
I think there is no other easy way to do that.
If you wants to know which process open which file, you may try to use the
handle tool in the sysinternals website.
e.g. if you have open the testworkbook.xl s with excel.exe, you can use the
command line as below.
handle testworkbook
And you will get the output as below.
EXCEL.EXE pid: 608 E:\Test\TestWor kBook.xls
Then you can parse the output to get the result.
Hope this helps.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Hi
I think there is no other easy way to do that.
If you wants to know which process open which file, you may try to use the
handle tool in the sysinternals website.
e.g. if you have open the testworkbook.xl s with excel.exe, you can use the
command line as below.
handle testworkbook
And you will get the output as below.
EXCEL.EXE pid: 608 E:\Test\TestWor kBook.xls
Then you can parse the output to get the result.
Hope this helps.
Best regards,
Perter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shawn |
last post by:
Hi.
I'm using a FileStream (instead of just the path to the xml file) to load an
XmlDocument. I'm doing this because I need to be able to prevent other
processes to update the file I'm working on. The problem is that I'm
getting multiple processing instructions and multiple root elements in my
xml file when I use a FileStream. Here is an example:
test_1.xml contains:
<?xml version="1.0" encoding="utf-8"?>
<root>
|
by: Tom |
last post by:
I am working with the this object as oppose to the
StreamReader object becuase I need to access a file (to
find the contents) while an external application is
updating the file. When I was working with the
StreamReader object I got a deadlock when I tried reading
the file while my external application was writing to it.
So far I am able to create a FileStream object and open
the file in question (CrawlerBackup.txt).
But I am unable to...
|
by: Chris Fink |
last post by:
How do I load a string into a FileStream without going to disk?
For example,
string abc = "This is a string";
How do I load abc into a FileStream?
FileStream input = new FileStream(.....);
|
by: majiofpersia |
last post by:
Hi Everyone and thanks in advance,
I am trying to create a webservices which will read a binary file and create
another file based on that first one and sends back the new file to the
client. The thing is that I don't want to at any time save this file on the
server ... I want to do all this in memory if possible. I have two
questions:
1) What do you think about this method? Specially if the clients are web
clients ... will this...
|
by: lh |
last post by:
The following method only works when i give the ASP.net account full
permissions on the directory.
It doesn't work when i give the directory Modify, Read &Execute, List Folder
Contents, Read, and Write permissions (all at the same time)
I'm only trying to READ the file. Why do i have to give it full
permissions?
public static string ReadFileContents(string filePath)
{
| |
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 allowed.
|
by: Nathan Sokalski |
last post by:
I am having a problem saving an image with the same name it originally had. I have two similar versions of my code, one in which I close the FileStream used to open the original image before saving, the other in which I close the FileStream afterwards, although both return the same error. Here are the two versions of the code and the errors they each return (NOTE: I rebooted immediately before running each of these versions so that I knew they...
|
by: Tim_Mac |
last post by:
hi,
i'm not sure if i have chosen the best approach, but it seemed quite
good to me.
i have a collection class, containing business objects. the collection
class is static and remains in-memory all the time the app is running.
it is persisted to an Xml file when necessary. i keep a static
filestream on the xml file. the advantage of this is that i can lock
the filestream object to prevent concurrent reading/writing.
the code works...
|
by: rn5a |
last post by:
What's the difference between the 'Stream' object & the 'FileStream'
object?
A file can be opened using the following code snippets:
--------------------
'create a File object & StreamReader
Dim objFile As New File(Server.MapPath("Page1.html"))
Dim sReader As StreamReader
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |