How to fix windows cannot be installed on GPT partition style disk.

You may get this error when you installing Windows 7, 8 or 8.1, Booting from GPT is only supported for 64 bit editions of Windows  vista, 7,8, & 8.1 on UEFI based systems. lets get this fixed.

Continue reading

Advertisements

Find your device model and serial number using command prompt

How to find your computer/ laptop model

Open the command prompt and type the following command

 wmic bios get serialnumber

if you want to get more details use following command.

 wmic csproduct get name, identifyingnumber

to add vendor name to above result enter this command.

 wmic csproduct get name,vendor,identifyingNumber

utf-8 Optimized Encryption and Decryption in .Net

we know that in our applications, both web and desktop we need to use encrypting and decrypting functionalities. but problem is how strong your encryption is. and how you are going to manage url  encode and  url decode against encrypted content.  Continue reading

Toggel visibility of Div tag in Asp.net easy way

usually most developers use J Query/CSS to toggle the visibility of webpage elements. for example a DIV tag, however even it is not visible in a webpage, if you examine the source code you will be able to see the div tag in source code. because it is already being rendered by server. however in asp.net we can use following code to do the same trick.


Page.FindControl("YourDivId").Visible = false;

Advantage of using this way is,

  • Easy to use.
  • Server do not render the div tag. completely invisible, even to java script web crawlers
  • Most of all its pure .Net. no need to write too many lines of code. simple yet powerful

FTP File Upload in C#

this is a simple FTP file upload example

you can set your proxy credentials using request.Proxy;

private static void UploadFile(string dir, Uri target, string fileName, string username, string password, string finilizingDir, string startupPath, string logFileDirectoryName)
            {
                try
                {
                    // Get the object used to communicate with the server.
                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
                    request.Proxy = null;
                    request.Method = WebRequestMethods.Ftp.UploadFile;

                    // logon.
                    request.Credentials = new NetworkCredential(username, password);

                    // Copy the contents of the file to the request stream.
                    StreamReader sourceStream = new StreamReader(dir + "\\" + fileName);
                    byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
                    sourceStream.Close();
                    request.ContentLength = fileContents.Length;

                    Stream requestStream = request.GetRequestStream();

                    requestStream.Write(fileContents, 0, fileContents.Length);
                    requestStream.Close();

                    FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                    if (response.StatusCode == FtpStatusCode.ClosingData)
                    {
                       Console.WriteLine(" --> Status Code is :" + response.StatusCode);
                    }

                     Console.WriteLine(" --> Upload File Complete With Status Description :" + response.StatusDescription);

                    response.Close();
                }
                catch (Exception ex)
                {
                     Console.WriteLine("*** Error Occurred while uploading file :" + fileName + " System Says :" + ex.Message + " **********END OF ERROR**********");
                }
            }


Dynamically Build Entity Framework Connection At Runtime

sometimes you may need to build your entity framework based connection dynamically during the run time instead of using app.config file.

note that you need to add following using statements

using System.Data.SqlClient;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;

using System.Data.SqlClient;
using System.Data.EntityClient;
using System.Data.Metadata.Edm;

 internal static EntityConnection GetConnection()
        {
            // Specify the provider name, server and database.
            string providerName = "System.Data.SqlClient";
            string serverName = GetServerName() ;
            string databaseName = GetDatabaseName();

            // Initialize the connection string builder for the
            // underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
            new SqlConnectionStringBuilder();

            // Set the properties for the data source.
            sqlBuilder.DataSource = serverName;
            sqlBuilder.InitialCatalog = databaseName;
            sqlBuilder.UserID = userID;
            sqlBuilder.Password = password;

            // Build the SqlConnection connection string.
            string providerString = sqlBuilder.ToString();

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
            new EntityConnectionStringBuilder();

            //Set the provider name.
            entityBuilder.Provider = providerName;

            // Set the provider-specific connection string.
            entityBuilder.ProviderConnectionString = providerString;

            // Set the Metadata location.
            entityBuilder.Metadata = @"res://*/MetaModel.csdl|
            res://*/MetaModel.ssdl|
            res://*/MetaModel.msl";
           

            EntityConnection conn = new EntityConnection(entityBuilder.ToString());

            return conn;


        }

Usage Of this Method


       using (var contxt = new YourDatabaseEntities(GetConnection()))
       {
         // your code go here.       
       }

Happy Coding.. !!