17-10-12, 05:24 PM
كاتب الموضوع : AhmedEssawy
لانشاء مجلد بالاعتماد علي APIs
كود :
[align=left][FONT=Calibri][FONT=Courier New][[color=teal]DllImport[/color]([color=maroon]"kernel32.dll"[/color], EntryPoint=[color=maroon]"CreateDirectoryA"[/color])][/FONT][/FONT]
[FONT=Calibri][FONT=Courier New][color=blue]public[/color] [color=blue]static[/color] [color=blue]extern[/color] [color=blue]bool[/color] CreateDirectory([color=blue]string[/color] lpPathName, [color=teal]SECURITY_ATTRIBUTES[/color] lpSecurityAttribut);[/FONT][/FONT][FONT=Calibri]
[color=green][FONT=Courier New]// This creates a directory if possible, and updates the status in the function [/FONT][/color]
[FONT=Courier New][color=green]// output text box.[/color][/FONT]
[FONT=Courier New][color=blue]private[/color] [color=blue]void[/color] btnCreateDirectory_Click([color=blue]object[/color] sender, System.[color=teal]EventArgs[/color] e) [/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][color=teal]Win32API[/color].[color=teal]SECURITY_ATTRIBUTES[/color] security = [color=blue]new[/color] [color=teal]Win32API[/color].[color=teal]SECURITY_ATTRIBUTES[/color]();[/FONT][/FONT][/align]
[FONT=Calibri]
[align=left][FONT=Courier New][color=blue]if[/color] ([color=teal]Win32API[/color].CreateDirectory(txtDirectory.Text, security))[/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]txtFunctionOutput.Text = [color=maroon]"Directory created."[/color];[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New][color=blue]else[/color] [/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New]txtFunctionOutput.Text = [color=maroon]"Directory not created."[/color];[/FONT]
[FONT=Courier New]}[/FONT]
[FONT=Courier New]}[/FONT][/align]
[/FONT]