Tuesday, 28 June 2011

Design time error: In this mode, command line arguments will not be passed


problem

c# idiot fucken error!!! (microsoft SUCKS)
---------------------------
The current project settings specify that the project will be debugged with specific security permissions.  In this mode, command line arguments will not be passed to the executable.
Do you want to continue debugging anyway?
[Yes]   [No]  
---------------------------
difficulty level

3/10 :|
compatibility

vs2008 .net 2.5
solution

- open the properties of the application
- go to at security tab
- click "Enable ClickOnce security settings"
- select "This is a partial trust" (at the end you may turn it back)
- Under all these, there is a button "Advanced" where it is not displayed sometimes if your monitor has lo resolution, scroll down to see it, press it and there you may find the settings if you with to use this "permission set" on debug execution. If you selected to use this settings you cannot use the specified command line arguments at "debug" tab of the parameters (one more reason why Microsoft sucks). Your application will use the command line arguments finally in "release" version. Who fucks Microsoft anyway, add some code to feed your application with the command line argument from inside your code. This is not so professional but with Microsoft we can't be professionals anyway!
- SAVE the parameters window and then ReBuild!

Runtime error Request for the permission of type 'System.Security.Permissions.FileIOPermission

problem

c# security fucken error!!! (microsoft SUCKS)
---------------------------
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
difficulty level

3/10 :|
compatibility

vs2008 .net 2.5
solution

- be sure that the file you are trying to open it from you code, is in the same directory or somewhere where is valid to reach- open the properties of the application
- go to at security tab
- click "Enable ClickOnce security settings"
- select "This is a partial trust"
- Zone your application: (custom)
- Select above all the secutiry settings required from the environment where the application will run (consider about this!). You must include FileIOPermission if your application open files. Do not include regardless permissions because in case where the end user hasn't them (i.e. guest user) your application will not run.
- Under all these, there is a button "Advanced" where it is not displayed sometimes if your monitor has lo resolution, scroll down to see it, press it and there you may find the settings if you with to use this "permission set" on debug execution. If you selected to use this settings you cannot use the specified arguments at "debug" tab of the parameters (one more reason why Microsoft sucks). Your application will use the command line arguments finally in "release" version.
- SAVE the parameters window and then ReBuild!
- open the file c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config ; this key and update accordingly: <trust level="Full" originUrl=""/>

Printing the Form (Visual C#)

This example demonstrates printing a copy of the current form.
You may also use the PrintDocument component instead of PrintForm component with the same way.

This technique captures the gdi handler of the form and pastes it as image to the printer (as bitmap). It is not so good idea because the image has no good quality! If you plan to print photos and other material that requests high quality forget this technique and start to play drawing in the printer's canvas (i will show you in another post it is very easy).

Lest CODE!

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{

Thursday, 23 June 2011

how to handle files, directories and drives

problem

c# - how to handle files, directories and drives --- Working with the File Type --- in practice! >>guide<<
difficulty level

3/10 :|
compatibility

flex 4.0
solution

Method Meaning in Life
ReadAllBytes() Opens the specified file, returns the binary data as an array of bytes, and then closes the file
ReadAllLines() Opens a specified file, returns the character data as an array of strings, and then closes the file
ReadAllText() Opens a specified file, returns the character data as a System.String, and then closes the file
WriteAllBytes() Opens the specified file, writes out the byte array, and then closes the file
WriteAllLines() Opens a specified file, writes out an array of strings, and then closes the file
WriteAllText() Opens a specified file, writes the character data, and then closes the file
Using these new methods of the File type, you are able to read and write batches of data in just a few lines of code. Even better, each of these new members automatically closes down the underlying file handle. For example, the following console program (named SimpleFileIO) will persist the string data into a new file on the C drive (and read it into memory) with minimal fuss:

using System;
using System.IO;   // important!
class Program
{
  static void Main(string[] args)
  {
    Console.WriteLine("***** Simple IO with the File Type *****\n");
    string[] myTasks = {
    "Fix bathroom sink", "Call Dave",
    "Call Mom and Dad", "Play Xbox 360"};
    // Write out all data to file on C drive.
    File.WriteAllLines(@"C:\tasks.txt", myTasks);
    // Read it all back and print out.
    foreach (string task in File.ReadAllLines(@"C:\tasks.txt"))
      Console.WriteLine("TODO: {0}", task);
    Console.ReadLine();
  }
}

how to pass command line arguments in the main form of an application

1. open the "program.cs" file form solution explorer of vs

2. in the follow code... add the red marked text
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain(args));  //Your Form might not named FormMain
        }

3.  Open your Main Form -> right click -> view code, to see the actual code

4. Modify the follow code, add again the red marked text
        public FormMain(string[] args)           //Your Form might not named FormMain

At this point in the FormMain contructor the args string array contains the command line arguments.
How to add arguments now in VS?

5. From solution explorer of vs -> double click the "properties" node -> click on "debug" tab -> type your arguments in "command line arguments" box