|
Try this:
(file is a FileInfo object)
if(file.Attributes == FileAttributes.ReadOnly)
{
}
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
Have you test this one Rickard?
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
As I said to you in my reply... your answer is the right one!
And no, I have not try that... I just thought that would be how you found out if it was read only or not!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
your code can pass the compiler.
but if the file have another attribute besides "readonly",your code can't work right.
|
|
|
|
|
i had a similar problem, i need to check if a file is a Directory, but ignore directory’s with System and/or Hidden attributes.
Thought my solution might be of some use if you need an example of how to check for more than one attribute. Also as i only started using C# 2 days ago maybe some expert can tell me if my solution is the best for what I’m trying to do, or if there is simpler method.
FileAttributes att = fsi[i].Attributes; //fsi = array of FileSystemInfo
bool bDirectory = (!((att & FileAttributes.Hidden) !=0) && // dont want hidden folders
((att & FileAttributes.Directory) !=0) &&
!((att & FileAttributes.System)!=0)); // dont want system folders
if(bDirectory)
//do something with fsi[i] - a directory
|
|
|
|
|
How can I globally share variables across forms?
i.e. - form2 sets a variable that form1 can use and vice versa
Thanks
Nick Parker
|
|
|
|
|
With a property can you do that.
I have done that!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C# and C++!
|
|
|
|
|
A good method is using a singleton class that is loaded on demand.
MyAppSettings - a class that is the equivalent of a global variable:
public class MyAppSettings {
// make private since class should not be intatiated directly
private MyAppSettings() {
// ...
}
// this one property
public string Setting1 {
get {
// read the data from a database or from a file
}
set {
// save the data to a database or file
}
}
private static MyAppSettings _settings = null;
public static MyAppSettings Instance {
get {
if (_settings == null)
_settings = new MyAppSettings();
return _settings;
}
}
}
Not only does this class define global variables, but it insures that only one instance of the data is floating around.
To access you global data:
MyAppSettings.Intance.Setting1 = "xyz";
hope this helps
|
|
|
|
|
Is there a way I can use an object without knowing which object it realy is? for exemple: I have several objects that implement IEnumerable(these objects has arrayList), I need to Implement IEnumerator and I want to do it once. but I don't know for which object I implement it for so when I do : object.arrayList[i] -its an error.
(object doen't have an arrayList property). how can I do it???
thanks in advance , sharon
|
|
|
|
|
Ahhh, the beauty of programming via interfaces [contractual I think is the term]
IEnumerable ie = myobject as IEnumerable
if( ie != null )
{
IEnumerator = ie.GetEnumerator();
...
} HTH,
James
Simplicity Rules!
|
|
|
|
|
I need to know how to call the following win32 api from c#
<br />
BOOL SystemParametersInfo(<br />
UINT uiAction,
UINT uiParam,
PVOID pvParam,
UINT fWinIni
);<br />
I tried with the following PInvoke syntax
<br />
[DllImport("user32.dll")]<br />
public static extern bool SystemParametersInfo(int uiAction,<br />
int uiParam,object pvParam,int fWinIni);<br />
Is substituting object for pvoid okay, where can I find more Info. on this (how do i do substituiton) other than msdn.
Now I need to pass on the address of a Rect to the above function...
the exact win32 api call looks like this...
<br />
::SystemParametersInfo(SPI_GETWORKAREA, 0, &rectSomething, 0);<br />
How do i do this in C#.
Thanks
Kannan
|
|
|
|
|
Kannan Kalyanaraman wrote:
Is substituting object for pvoid okay
No! Use IntPtr instead.
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Does anybody know how can I find out which window has the focus from my program?
Thanks
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Mazdak wrote:
Does anybody know how can I find out which window has the focus from my program?
You'll have to invoke the API I guess
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish - Native CPian wrote:
You'll have to invoke the API I guess
You mean .NET does not have something for that I have to use win32? I don't like it if I have to do it that way.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Mazdak wrote:
You mean .NET does not have something for that I have to use win32? I don't like it if I have to do it that way.
I might be wrong Mazy! I guess we both can wait for James Johnson to come back from his weekend trips to answer this question!
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish - Native CPian wrote:
I guess we both can wait for James Johnson to come back from his weekend trips to answer this question!
Yes,we have to wait for C# man of CP.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
Mazdak wrote:
Yes,we have to wait for C# man of CP
Cool! James - The CP C#er
Nish
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|
Nish - Native CPian wrote:
James - The CP C#er
LOL!
James
Simplicity Rules!
|
|
|
|
|
Mazdak wrote:
Does anybody know how can I find out which window has the focus from my program?
If you are talking about just getting the currently active WinForm in a non-mdi application it would be
System.Windows.Forms.Form.ActiveForm
If you wish to know which control it would be
AciveForm.ActiveControl
For a MDI it would be
System.Windows.Forms.ActiveMDIChild
If you are referring to any windows external to your application, I believe you will need to use the Win API.
Rocky Moore
|
|
|
|
|
Thank you Rocky.
Rocky Moore wrote:
If you are referring to any windows external to your application
Yes,I want external windows.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
As Nish said, and you feared; you have to resort to the Win32 API. This is because you can't create a Control object (the base class for Form ) from an arbitrary HWND, only for one which a Control object already exists.
Perhaps in V.NEXT we'll have such support for a limited window class
James
Simplicity Rules!
|
|
|
|
|
Thank you James.
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
I know this is a very basic question but could someone please tell me how to create for example a dialog box for getting user settings ect for my application, or even an about dialog box. Is it as simple as right clicking in the explorer and adding another windows form? If so how do I get my program to display it?
Thanks in advance,
Paddy.
|
|
|
|
|
Paddy wrote:
Is it as simple as right clicking in the explorer and adding another windows form?
Yes.
Paddy wrote:
If so how do I get my program to display it?
YourFrm frm = new YourFrm();
frm.ShowDialog();
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|