Sorry for overlooking the detail when I pasted the code. But my original attempt included "|". I just tried now instantiating "perm" object like below: var perm = new FileIOPermission(FileIOPermissionAccess.Write, directory);
But still no luck. - Malhar
malharone
Posts
-
C# - File Permission -
C# - File PermissionThis is a very trivial question, but I have not had much chance in finding a solution. I have searched Google / blogs, but apparantly either there is no solution or I searched for the wrong keyword. Any help will be greatly appreciated. I have an application (similar to a wizard) and I need to validate whether the user has the permission to write/read from a particular location. I the following function (below), but I am always getting the value "true" eventhough from Windows Explorer when I try to navigate to the location, I'm always getting an error (eg. "You need permission to perform this action. [Retry] [Cancel]").
static bool CanReadAndWrite(string path)
{
var perm = new FileIOPermission(
FileIOPermissionAccess.Write &
FileIOPermissionAccess.Read &
FileIOPermissionAccess.PathDiscovery,
path);
try
{
perm.Demand();
return true;
}
catch
{
return false;
}
}Many of the blogs/articles suggest that I should attemt to write to the location anyways, and if the write operation is successful, then I can proceed to write the main data. If there is an exception creating the stram then there is a perimission issue. But this solution would NOT work for me. The application has two "pages". - First wizard page: user selects the file path - Second wizard page: specify options - Third wizard page: write data Each of the pages has Cancel button and the expectation is that user NOT be able to continue to the 2nd page if permission is denied. The above suggested solution would WORK fine if the user does not have permission. But if the user DOES have permission, then the validation check in Page # 1 would have created new file and/or overwrote an existing file with 0 bytes -- and if user cancels on Page #2 then there is a useless file on the file system. So anyways, what should I do (clean implementation) to check for file permision? I'm using Vista, .Net 3.5. Thanks, - Malhar
-
Multiple instances of NTService process [modified]Yup.. there was a great startup article .. this solved the problem! http://osdir.com/ml/windows.devel.dotnet.general/2002-05/msg00446.html[^] - MS
-
Multiple instances of NTService process [modified]Just when I thought all the coding is done, i've hit a brick wall .. It's CP to the rescue :) I have an NT Service ("Windows Service") which does some processing based on a configuration file. I can install and uninstall this NT service using installutil without any problem. However, I need to be able to run multiple instances of the same NT Service each with various param. E.g.
service1.exe /config1.xml
service1.exe /config2.xml
service1.exe /config3.xmlI have tried modifying the install-script and pass param: e.g.
installutil /i "service1.exe /config1.xml"
This installs, but when I look at the actual registry value under HKLM\System\CurrentControlSet\Services\Service1, the "ImagePath" key does not contain the additional arg I passed at install-time. Then I manually modified the registry-key to include the additional arg, but I still cannot run subsequent installutil. It fails with "The specified service already exists" error. How can I install multiple process instances of this Windows NT Service ? (Windows does runs multiple instances of "svchost.exe" without any problem) Due to some constraints I cannot a) consolidate the logic and run as single process multiple threads or b) consolidate the logic and run as single process multiple app-domains or c) create multiple copies of the binaries in N different locations. I look forward to your responses. - Malharmodified on Tuesday, June 3, 2008 5:16 PM
-
Developers on MySpaceI almost joined MySpace team but there was a lot of resistence from the family due to their recent controversies. But I've never used MySpace (nor have profile) and that was the first thing I told the mgr. -- he said, "ditto". Use MySpace only for testing for the new features they've created :).
-
An architect should code. PeriodI still code -- not as heavily as I used to.. I just try to maintain a good balance between my roles. - Malhar
-
Bug in Excel 2007Valid bug! I can reprod it.
-
How would you code it?Big Daddy Farang wrote:
I think he's fishing for "5" votes.
In that case, he'd asked for "vote 5 for option 1. vote 5 for option 2" !. - MS
-
How would you code it?Agree. I prefer the first approach for two reasons: - Readablility: (in my opinion) - Performance: string concat. is heavy, which does not happen in the string.format - Localization: it's easier to put the Format string in your RESX file and depending upon the locale, one can re-order the "{xx}".
-
Do you add change history in source code? why?Yes and no. We use TFS's attach work-item feature so that we don't have to manually enter this information everytime. But this approach is more time consuming than what we'd been doing for years. anyways, I've gotten in the habit of doing both and so far it has worked out well.
-
a chinese poemGuys come on .. we've gotta use the tools of the trade .. google translate! I thought it'd be faster than me trying to learn Chinese! Here's translated version: http://www.codeproject.com/lounge.asp?msg=2233742#xx2233742xx - Malhar
-
a chinese poem -
a chinese poemUsing Google translate: Tomorrow I will no longer have beautiful Autumn will dry my love interest Tonight is about ending the stars Drizzle is kept hidden teardrop I had the flowers of your heart Flower fragrance you my heart Yat - But tomorrow I will not have the beautiful You weep for the dead flowers Google translate rocks! - Malhar
-
How can Apple get away with this?If the rebate is from Apple then why do they care whose service you're using? As long as you purchased their product you should be entitled to the rebate. I can't imagine how many people would be pissed with this. - Malhar
-
How can Apple get away with this?Apple's $100 iPhone credit won't buy iTunes music[^] Not that I've purchased I phone and nor that this doesn't really concern me directly but if it were Microsoft, media would've been all over it with some anti-trust lawsuit! - Malhar
-
Help with SQL Server (NOT A programming question) [modified]I'm way below in the hierarchy. So any suggestions for articles?
-
Help with SQL Server (NOT A programming question) [modified]He's at a highler level than I am in the hierarchy of things so my voice has no opinion to the management. Furthermore, the "varchar" for boolean strangely made into the "SQL Standards" document in the company (before I joined) and even more strangely it got approved. So as of now, I look like a clueless idiot! This is so obvious, may be that's why I wasn't able to find any links/articles. Any suggestion would be greatly helpful.
-
Help with SQL Server (NOT A programming question) [modified]:) .. it's not that bad! Our disagreement is on booleans. Though he wants me to textualize enums and store their text values as strings instead of storing the numeric representation. Currently, we don't use [flags] on enums and we are too scared of renaming the enum so it has been working out so far. Anyways, he's at a highler level than I am in the hierarchy of things so my voice has no opinion to the management. Furthermore, the "varchar" for boolean strangely made into the "SQL Standards" document in the company (before I joined) and even more strangely it got approved. So as of now, I look like a clueless idiot! This is so obvious, may be that's why I wasn't able to find any links. Any suggestion would be greatly helpful.
-
Help with SQL Server (NOT A programming question) [modified]I need some strong supportive arguments to use "bit" field type in a SQL Server 2000/2005 table to store boolean values. Our application is in WPF with C# & XAML. Our DBA wants to use char(1) field with constraints of 'Y','y','N','n' in the database which uses Latin1_General_CS_AS (case sensitive/accent sensitive) collation. I am baffled by the suggestion of the DBA. In my past experience, I've never heard of such a wild idea. The DBA proposes the char(1) field type because of two reasons: 1) When an admin looks at the table, 'Y','N','y','n' are more obvious than 0 and 1. (But then again, if one does not know 0 & 1 (for bit field) then s/he shouldn't be admin in the first place)! 2) In HIS past projects, he used char(1) and no one complained. My problems are.. - This breaks all the queries/SQL that has been written to do true/false (0/1) comparison. - Unlike bit field (which only has two values), another isuse wih char is that unless someone explicitely looks at the constraint, there is no clea indication that the field only accepts Y & N. - Bit is CLR/SQL compliant. - Char is more expensive (size & equality comparison wise) than bit. - The mapping will have to be changed in my business objects from boolean to string or char. - UI will have to introduce some new logic for converting char/string to boolean for displaying radio/checkbox options .. :( So anyways ... any suggestions? or links to Microsoft/publication white papers? I'd really like have some articles to back my argument. Thanks, - Malhar -- modified at 17:23 Monday 10th September, 2007
-
utility: e-mail new errors from event logYes I made it as my first "commercial" project. It allowed you to set configuration (e.g. Source, Entry Type, rules -- e.g. Contains/Doesnot contain) .. let me see if it is still available. - MS