Wednesday 28 March 2018

How to create collection and drop collection in Mongodb 3.6?

To create collection in Mongodb 3.6 command is:-

The createCollection() Method

db.createCollection(Name, Options)

Name:- String Name of the collection to be created
Options:- Document(Optional) Specify options about memory size and indexing

Note:- 

In MongoDB, you don't need to create collection. MongoDB creates collection automatically, when you insert some document.

You can check the created collection by using the command show collections.

e.g.
use practice
show collections

The drop() Method

MongoDB's db.collection.drop() is used to drop a collection from the database.

Syntax

Basic syntax of drop() command is as follows −
db.collectionName.drop()

drop() method will return true, if the selected collection is dropped successfully, otherwise it will return false.

Tuesday 2 October 2012

How to replace text in file in .Net?

Definition: How to replace text in file?

Method:
1) Add namespace
    using System.IO;

Code:
 protected void btnReplace_Click(object sender, EventArgs e)
    {
        string sfileName = string.Empty;
        sfileName = "F:\\Work\\HTML\\Profile.txt";

        File.WriteAllText(
            sfileName,
            File.ReadAllText(sfileName)
                .Replace("Name", "Abhishek")
                .Replace("Address","Block No.123,LBS Road,Mumbai,Maharastra")
                .Replace("Mobile", "93117481253")
       );

    }


How to unzip file in .Net?

Definition: How to unzip file in .Net?

Method: 


1) Add the Ionic.Zip dll through Add reference

2) Add the NameSpaces (using Ionic.Zip;)

In my previous post I show you how to make zip file. Now I will show you how to unzip that zip folder.

Code:
 protected void btnUnZip_Click(object sender, EventArgs e)
    {
        String TargetDirectory = "f:\\Zip\\myzip.zip";

        using (ZipFile zip1 = ZipFile.Read(TargetDirectory))
        {
            zip1.ExtractAll("f:\\UnZip\\myzip",
            Ionic.Zip.ExtractExistingFileAction.DoNotOverwrite);
        }
        File.Delete(TargetDirectory);  //Delete myzip.zip file. It is optional. If you want to delete
                                                         //then delete else don't delete.
    }


How to do zip in .Net? How to make zip file in .Net?

Definition: Make zip file.

Method:
1) Add the Ionic.Zip dll through Add reference

2) Add the NameSpaces (using Ionic.Zip;). 

Code: 

A) Following method will zip whole folder.

protected void btnZip_Click(object sender, EventArgs e)
    {
        string zipfilename = @"f:\\zip\\myzip.zip";  //zipped file name
        string filename = @"F:\\myfiles";         //folder to be zip

        using (ZipFile zip = new ZipFile())
        {
            zip.AddDirectory(filename);
            zip.Save(zipfilename);
        }
    }

Output:
myzip.zip folder at F: drive.

B) Following method will add selected file and folders from different path and add it to archive folder.
 
 protected void btnZip_Click(object sender, EventArgs e)
    {
        string zipfilename = @"f:\\unzip\\myzip.zip";   //zipped file name

        string filename = @"F:\\myfiles";                //folder to be zip

        using (ZipFile zip = new ZipFile())
        {
            //// add this map file into the "images" directory in the zip archive
            zip.AddFile("F:\\Food\\files\\0.png","images");

            //// add the report into a different directory in the archive
            zip.AddFile("F:\\Recipe", "Files");

            zip.AddDirectory("f:\\ticket", "Ticket");


            zip.Save(zipfilename);
        }
    }



Output:
myzip.zip folder at F: drive.
This zip folder will contain 3 folders i.e. images, Files and Ticket.

You run one by one each code and you can see difference between 2 methods.














Tuesday 29 May 2012

How to prepare appam in kerala style? Appam recipe

Kerala Appam recipe

Ingredients for Appam recipe

2  cup(s) raw rice soaked for 4-5 hours
4  cups coconut shavings
1  cup(s) cooked rice
a pinch of yeast granules dissolved in some coconut water or little hot water
salt and sugar to taste

How to make Appam?

Drain the soaked rice and grind it along with the coconut shavings and cooked rice to a fine thick paste. Do not add too much water. Coconut water may be preferably used instead of water for grinding. Add the yeast and mix lightly. Mix in the salt and sugar to taste. Allow to ferment at room temperature for at least 6 hours.
Heat a small non-stick wok. Pour approximately half a cup of batter and quickly but gently swirl the pan around such that only a thin layer of the batter covers the sides and a thick layer collects at the bottom. Cover with a lid and cook each appam on medium heat for about 3 minute(s) or till the edges have become golden crisp and the centre is soft and spongy. Another sign of doneness would be when the edges start coming off the wok.


Serve it with vegetable stew or chicken stew or egg curry.

Friends I am sure that you will love this recipe. I love it. I prefer you to eat little bit hot.


Kerala appam
Appam


 

 

How to fetch TextArea value in .ashx file?

Definition: Fetch Textarea control value in .ashx file.

Example:
.Ashx file code:-

public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/html";
        try
        {
                  var comment = context.Request.Params["ctl00$ContentPlaceHolder1$txtComment"];                      context.Response.Write(comment);
         }
        catch { }
    }


Note:
contentplaceholder : because i have used Master Page.

Wednesday 16 May 2012

How to send email in .Net?or how to send an email from a Gmail address using SMTP server?

Definition: SMTP Server

SMTP protocol is used for sending email . SMTP stands for Simple Mail Transfer Protocol. System.Net.Mail namespace is used for sending email . We can instantiate SmtpClient class and assign the Host and Port . The default port using SMTP is 25 , but it may vary different Mail Servers .
The Gmail SMTP server name is smtp.gmail.com and the port using send mail is 587 and also using NetworkCredential for password based authentication.

Following example shows how to send email in .Net? or How to send email by using your gmail email id?


Example:


using System.Net.Mail;
 
private void SendMail_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("your_gmail_id@gmail.com");
                mail.To.Add("To_emailid@xyz.com");
                mail.Subject = "Test Mail";
                mail.Body = "This is for testing SMTP mail from gmail.";

                SmtpServer.Port = 587;
  SmtpServer.Credentials=new System.Net.NetworkCredential("your_gmail_id@gmail.com", "your_gmail_id_password");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
                MessageBox.Show("Mail Send Successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }