Saturday 23 July 2011

C# How to Create a text.txt

In this section we going to discuss about how we going to create a text file *.txt by using C#.
The commands we going to used is StreamReader. Before that remember add a library using System.IO;

Programming Look Like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace Try_an_Error
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();      
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!textBox1.Text.Equals(null))
            {
                StreamWriter Password = File.CreateText("C:\\Users\\patrick\\Deskt
                \\"+textBox1.text+".txt");
            }
        }    
    }
}

C# Unlock Folder

At last section, we going to share about how to lock the folder. Now in this sections I going to share you about how we going to unlock the folder. This is also very simple where we only need to delete the CLSID.
Lock Folder add CLSID, unlock Folder delete CLSID.
How we going to delete the CLSID? We still using the rename mated to erase the CLSID.
Directory.MoveTo(folderBrowserDialog1.SelectedPath.Substring(0, folderBrowserDialog1.SelectedPath.LastIndexOf("."))); msdn

Programming Look Like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace Try_an_Error
{
    public partial class Form1 : Form
    {
        string WindowSecurity = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";
        public Form1()
        {
            InitializeComponent();
           
        }
       
        private void button1_Click(object sender, EventArgs e)
        {
           
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                if (folderBrowserDialog1.SelectedPath.LastIndexOf(".{") == -1)
                {
                    listBox1.Items.Add("true");
                    textBox1.Text = folderBrowserDialog1.SelectedPath;
                    DirectoryInfo Directory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                    Directory.MoveTo(folderBrowserDialog1.SelectedPath + WindowSecurity);               
                }
                else
                {
                    DirectoryInfo Directory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                    Directory.MoveTo(folderBrowserDialog1.SelectedPath.Substring(0, folderBrowserDialog1.SelectedPath.LastIndexOf(".")));
                }

                }

        }
    }
}

C# Folder Lock

Last section we discuss about how to move a Folder and also how to rename a folder. Now we going to learn how to Lock the folder, we going to lock the folder WITHOUT any password. In this section we discuss about how to lock but we NOT discuss about how to unlock. So during you want try the program measure you create a new folder and delete it after lock.

Here we need to know what is CLSID. A CLSID is a globally unique identifier that identifies a COM class object. If your server or container allows linking to its embedded objects, you need to register a CLSID for each supported class of objects. msdn 

The CLSID we going to apply is window security {2559A1F2-21D7-11D4-BDAF-00C04F60B9F0}

This is very simple to lock the Folder without any password. We just move the file and rename the file New Folder to New Folder.{2559A1F2-21D7-11D4-BDAF-00C04F60B9F0}. Just add the .{2559A1F2-21D7-11D4-BDAF-00C04F60B9F0} at the back of the folder.

you also can try manually to add this CLSID code at the back of you folder name. The output will lock the folder.

Program Look Like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace Try_an_Error
{
    public partial class Form1 : Form
    {
        string WindowSecurity = ".{2559a1f2-21d7-11d4-bdaf-00c04f60b9f0}";
        public Form1()
        {
            InitializeComponent();
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
                DirectoryInfo Directory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                Directory.MoveTo(folderBrowserDialog1.SelectedPath + WindowSecurity);
            }
        }
    }
}
 

C# Move File or Rename File

Now i am going to share to you on how to move a file:
We going to move New folder (3) into New folder (2)

 DirectoryInfo Directory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
* this will return the folder we SELECT to be move

Directory.MoveTo(Directory.Parent.FullName + "\\New folder (2)\\New folder (3)");
* this is the commands to MOVE the file.
*Directory.MoveTo(the destination + \\New folder (3)");
* IF you want to RENAME just change the  New folder (3) to ANY name you want.

Programming Look Like
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace Try_an_Error
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
                DirectoryInfo Directory = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
                Directory.MoveTo(Directory.Parent.FullName + "\\New folder (2)\\New folder (3)");

            }
        }
    }
}

Friday 22 July 2011

c# Browse folder

Here is sharing how we going to display browse folder in the text box.
**Browse folder only, NO txt, xls and etc...
first you need to add using System.IO;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace Try_an_Error
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}

output look like this: