Click here to Skip to main content
15,893,790 members
Home / Discussions / C#
   

C#

 
GeneralRe: LightBox in Windows Application Pin
V.25-Jul-10 21:03
professionalV.25-Jul-10 21:03 
QuestionThreading or Services Pin
Vinay Varghese25-Jul-10 19:44
Vinay Varghese25-Jul-10 19:44 
AnswerRe: Threading or Services Pin
Arun Jacob25-Jul-10 20:07
Arun Jacob25-Jul-10 20:07 
Questionhow invisible text field show on click of check box without page post back:? Pin
220825-Jul-10 19:36
220825-Jul-10 19:36 
AnswerRe: how invisible text field show on click of check box without page post back:? Pin
V.25-Jul-10 20:44
professionalV.25-Jul-10 20:44 
GeneralRe: how invisible text field show on click of check box without page post back:? Pin
220825-Jul-10 20:53
220825-Jul-10 20:53 
GeneralRe: how invisible text field show on click of check box without page post back:? Pin
V.25-Jul-10 21:01
professionalV.25-Jul-10 21:01 
QuestionCheck if user can write and delete from a directory Pin
RCoate25-Jul-10 14:17
RCoate25-Jul-10 14:17 
In a Windows (C#) form, I need to check if the user has the required permissions to write and delete from a directory (that they select).
I have some code that will do the job, but it feels wrong.
I try writing and deleting a test file and if an exception is thrown, then the test fails.
I am a bit unhappy with using exception testing like this, but can't find any other method that does not require reams of code.

Does anyone have another method that does not require exception testing?

Here is my code.
WriteToLog(string Message, Enum LogType) is a general logging method that writes the first parameter to the log file identified by the second parameter.

private bool UserCanWrite()
{
    try
    {
        WriteToLog("Test", LogFiles.Test);

        string TestLogPath = "Failed.Log";

        if (BaseDirectory.Length == 0)
        {
            TestLogPath = string.Format("C:\\{0}", TestLogPath);
        }
        else
        {
            TestLogPath = string.Format("{0}\\{1}", BaseDirectory, TestLogPath);
        }

        FileInfo TestLog = new FileInfo(TestLogPath);
        TestLog.Delete();

        return true;
    }

    catch
    {
        MessageBox.Show("You Don't have Read, Write and Delete privileges on the selected Base Directory\n\nPlease have your System Administrator grant those privileges before proceeding", "Higher Level of Privileges Needed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        return false;
    }

AnswerRe: Check if user can write and delete from a directory Pin
Not Active25-Jul-10 15:37
mentorNot Active25-Jul-10 15:37 
GeneralRe: Check if user can write and delete from a directory Pin
RCoate25-Jul-10 20:07
RCoate25-Jul-10 20:07 
GeneralRe: Check if user can write and delete from a directory Pin
RCoate25-Jul-10 20:25
RCoate25-Jul-10 20:25 
GeneralRe: Check if user can write and delete from a directory Pin
Not Active26-Jul-10 1:22
mentorNot Active26-Jul-10 1:22 
AnswerRe: Check if user can write and delete from a directory Pin
PIEBALDconsult25-Jul-10 18:58
mvePIEBALDconsult25-Jul-10 18:58 
GeneralRe: Check if user can write and delete from a directory Pin
RCoate25-Jul-10 20:06
RCoate25-Jul-10 20:06 
GeneralRe: Check if user can write and delete from a directory Pin
PIEBALDconsult26-Jul-10 3:02
mvePIEBALDconsult26-Jul-10 3:02 
QuestionCapture streaming video - (create bitmap) Pin
Mark H Bishop25-Jul-10 11:41
Mark H Bishop25-Jul-10 11:41 
AnswerRe: Capture streaming video - (create bitmap) Pin
Mark H Bishop26-Jul-10 12:31
Mark H Bishop26-Jul-10 12:31 
Questionconvert an array of string Pin
mrkeivan25-Jul-10 10:59
mrkeivan25-Jul-10 10:59 
AnswerRe: convert an array of string Pin
harold aptroot25-Jul-10 11:05
harold aptroot25-Jul-10 11:05 
AnswerRe: convert an array of string Pin
Luc Pattyn25-Jul-10 11:20
sitebuilderLuc Pattyn25-Jul-10 11:20 
AnswerRe: convert an array of string Pin
PIEBALDconsult25-Jul-10 12:10
mvePIEBALDconsult25-Jul-10 12:10 
GeneralRe: convert an array of string Pin
Luc Pattyn25-Jul-10 12:55
sitebuilderLuc Pattyn25-Jul-10 12:55 
GeneralRe: convert an array of string Pin
PIEBALDconsult25-Jul-10 13:02
mvePIEBALDconsult25-Jul-10 13:02 
QuestionSecure storage Pin
L Viljoen25-Jul-10 9:02
professionalL Viljoen25-Jul-10 9:02 
AnswerRe: Secure storage Pin
Eddy Vluggen25-Jul-10 9:28
professionalEddy Vluggen25-Jul-10 9:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.