|
Hi Martin,
I did a test on XP, I didn't see a Network Printers, but got an UnauthorizedAccessException
on C:\System Volume\Information.
And of course you should use a try-catch: there is input/output involved, it can always
fail (some one/some process could move/delete a file/folder before you could click OK,
a network drive could suddenly get disconnected, etc.)
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Luc Pattyn wrote: And of course you should use a try-catch: there is input/output involved, it can always
fail (some one/some process could move/delete a file/folder before you could click OK,
a network drive could suddenly get disconnected, etc.)
Good tippage - thanks Luc (although one can't help but wonder what other nasties this control might be hiding!)
"On one of my cards it said I had to find temperatures lower than -8. The numbers I uncovered were -6 and -7 so I thought I had won, and so did the woman in the shop. But when she scanned the card the machine said I hadn't.
"I phoned Camelot and they fobbed me off with some story that -6 is higher - not lower - than -8 but I'm not having it."
-Tina Farrell, a 23 year old thicky from Levenshulme, Manchester.
|
|
|
|
|
Dear ALL,
I am in process of developing a network management appliction primarly based on WMI, I have this query "How can I retrive list of open network connections" by a specfic machine (such as open ports n all on a machine).
By either some conventional approach or using WMI?
Thank you!
M. Nauman Yousuf
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hello to all.
I am sorry in advanced if my problem is very basic and seem obvious to you.
My situation is as follows,
I want to open a log file in my application and write to it occasionally.
I want to write to it a regular text, not bytes, but a streamWriter doesn't have the option of opening
a file in a shared mode(so I can open another instance to read the file).
I need the two abilities together SO,
How do I open a file in shared mode(something the FileStream allows me),
and write to it strings as if to Console I/O(like StreamWriter enables me).
I thank in advanced for any help.
|
|
|
|
|
Create the FileStream object with desired access and pass it to streamwriter's constructor
|
|
|
|
|
Thanks man, this was very short and helpful.
where do I do the rating?
|
|
|
|
|
Just below the message there is 'Rate this message' at right corner. Thanks for voting
|
|
|
|
|
I thought you were going to vote for my previous reply.
|
|
|
|
|
Thanks man,
Still I am having a problem.
I can't open another instance of the same file for reading, I get an exception:
The process cannot access the file 'C:\Logs\log 2007-11-17_part1.log' because it is being used by another process.
the code I used to open the first file and the second file is as follows:
first:
try
{
_fileController = new FileStream(_fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
_fid = new StreamWriter(_fileController);
}
second:
fsArr[index] = new FileStream(fileName, FileMode.Open, FileAccess.Read);
How come I receive the error????
|
|
|
|
|
-- corrected 17-NOV-2007
IMO you should explicitly set FileShare values for all parties.
Either allow Read (if there are no writers), or ReadWrite (if at least one party will be
writing, your case).
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
First of all, the code you use to create a FileStream object creates new file so the second instance of your application will try to create file which was created by first instance and not open for reading.
Secondly, according to MSDN FileShare.Read: "Allows subsequent opening of the file for reading. If this flag is not specified, any request to open the file for reading (by this process or another process) will fail until the file is closed. However, even if this flag is specified, additional permissions might still be needed to access the file."
Finally, here is a solution for your problem: Simultaneously Write to and Read from the same file[^]
|
|
|
|
|
Hi Giorgi,
First of all, the code you use to create a FileStream object creates new file so the second instance of your application will try to create file which was created by first instance and not open for reading.
my second instance is only creating a new fileStream that will open an existing file(the one created before) for reading.
at list that is what I understand of it. please feel free to correct me if I am wrong.
thanks.
|
|
|
|
|
thank you very much Georgi,
the link you provided me indeed did the trick.
You were a lot of help to me.
|
|
|
|
|
Hello everyone,
I have what should be a relatively simple C# .NET 2.0 IE BHO that I am really struggling with. The goal of the BHO is to provide a hook when the users opens a web-page the HelloWorld! message appears.
I am using Visual Studio 2005 Profesional Edition and do the following:
1- Build Solution (F6)
2- Fire an Internet Explorer (IE)
3- (From Visual Studio) Debug -> Attach to Process...
4- Select the Internet Explorer (IE) that was started in 1.
5- Attach
At this point I can see in the StatusBar loading message for verious files.
If I am not mistaken at this point my simple BHO should be attached to the Internet Explorer (IE). when I move from the webpage to other pages I expect for the HelloWorld MessageBox to pop-up once the website is loaded. But sadly, nothing happens!
The codes are:
IObjectWithSite.cs
using System;
using System.Runtime.InteropServices;
namespace WebWatcher
{
[ComVisible(true),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("FC4801A3-2BA9-11CF-A229-00AA003D7352")]
public interface IObjectWithSite
{
[PreserveSig]
int SetSite([MarshalAs(UnmanagedType.IUnknown)]object site);
[PreserveSig]
int GetSite(ref Guid guid, out IntPtr ppvSite);
}
}
BHO.cs
using System;
using System.Collections.Generic;
using System.Text;
using SHDocVw;
using mshtml;
using System.IO;
using Microsoft.Win32;
using System.Runtime.InteropServices;
namespace WebWatcher
{
[
ComVisible(true),
Guid("8a194578-81ea-4850-9911-13ba2d71efbd"),
ClassInterface(ClassInterfaceType.None)
]
public class BHO : IObjectWithSite
{
private SHDocVw.WebBrowser webBrowser;
public void OnDocumentComplete(object pDisp, ref object URL)
{
System.Windows.Forms.MessageBox.Show("HelloWorld!");
}
#region WebWatcher Internal Functions
public int SetSite(object site)
{
if (site != null)
{
webBrowser = (SHDocVw.WebBrowser)site;
webBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
}
else
{
webBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
webBrowser = null;
}
return 0;
}
public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
IntPtr punk = Marshal.GetIUnknownForObject(webBrowser);
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
Marshal.Release(punk);
return hr;
}
#endregion
}
}
How can I see what files are been loaded when I attach the codes to the Internet Explorer? Is there any particular setting that I should set the Visual Studio to inorder ro be able to get result? Your help is greatly appriciated. Thank you very much and have a great weekend.
Khoramdin
-- modified at 12:51 Saturday 17th November, 2007
|
|
|
|
|
From the number of posts on this subject you seem to be over your head. Possibly its time to give it up and try another project.
only two letters away from being an asset
|
|
|
|
|
Hello Mark,
Thanx for your reply. Now, I know that my messages can be read by other! *wink* By the way, if it bothers you so much that I post here, I surly can stop and take my postings and problems to another forum since I don't mean to upset anyone.
Since you have been readin my posting, then you should know by know, that they are on the same subject but as I am spending more time reading about the issue, they are changing since I feel as I am getting closer to the source of the problem.
I was wondering if you got the MVP title by very same approach of moving to the next topic once you are stuck on one?!!! *wink*
Since we are on the same topic, let me ask you this. When a Class Library is Attached to a running process, then I guess I should NOT be able to delete the dll file since that file should be loaded and used with the running poccess? In my case I can delete the WebWatcher.dll file and that makes me think if the file is actually been attached! What are your thoughts on this? Any information would be appriciated, mate.
Happy thanx-giving, mate.
khoramdin
-- modified at 18:39 Saturday 17th November, 2007
|
|
|
|
|
Khoramdin wrote: I was wondering if you got the MVP title by very same approach of moving to the next topic once you are stuck on one?!!!
I'm not stuck, you are.
Khoramdin wrote: I surly can stop and take my postings and problems to another forum
Bye.
only two letters away from being an asset
|
|
|
|
|
hi all
I have found code that adds url pattern in the internet explorer (IE) Security Zone (Trusted Site) by implementing [code]IInternetSecurityManager [/code] interface.
now I want to change programmatically security level of trusted site that is like enabling or disabling ActiveX control and plugin etc.
please tell how can i do that.
thank u....
destined to win
|
|
|
|
|
I just install vs2005 on Vista,
--updated sp1 of vs, also
--sp1 of Vista for vs2005,
set the permission level on shortcut,
running as an admin,
But it still asking permission from admin ,
I know its not C# question ,
|
|
|
|
|
humdumof wrote: I know its not C# question
...then why did you ask it in the C# forum?
There is a Visual Studio forum on this site. It would be more appropriate to ask your question there.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
i need to set one image to tree view nodes and another image to inner sub-nodes
i am able to set image to node that are same to nodes and sub nodes but unable to set different image to inner sub node.
|
|
|
|
|
Define the images that your TreeView control uses by setting its ImageList property.
Set which image in the ImageList each node uses by setting the ImageIndex or ImageKey properties on each TreeNode object.
Read the documentation[^] for more information.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I am developing an window application and in am facing a problem in getting image in list view control
--------------------------
Name| image| age
--------------------------
i want to show small image icon in second columns data.
|
|
|
|
|
Have a look at this article[^].
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
how i can print form?
123
|
|
|
|