Thursday, December 7, 2017

Save Image in Sql Server Using C#


In this blog I will tell you that how to save image in Sql Server using c#. Here I will give you necessary steps to store image in sql server.

1)      Before we are starting to make application in C# firstly we need to create a table in sql server where we store out image. Here I will create a table named ImageTable in which I will store image. ImageTable contains two column one is imageID which will store id of image in image table. And other column which have name imageData is stored image in format of binary.

Here I will provide a sample sql code snippet to create ImageTable

create table ImageTable

(

     imageID int,

     imageData image

)

2)      Now import System.Data.SqlClient namespace in your project. This namespace provide you all necessary classes and interfaces which is necessary to establish connection to SqlServer.

3)      Create following methods and call it according to your requiremnt.

/// <summary>

        /// On click event of browse button write down following code. This

        /// Will display a open file dialog box which will ask to choose you

        /// image and will store path of image in textbox.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button1_Click(object sender, EventArgs e)

        {

            OpenFileDialog ofd = new OpenFileDialog();

            if (DialogResult.OK == ofd.ShowDialog())

            {

                textBox1.Text = ofd.FileName;   //storing path of image in textbox.

            }

        }

        /// <summary>

        /// On the click of SaveButton call saveImageInDataBase(int imgId) method

        /// which will save image in database.

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void button2_Click(object sender, EventArgs e)

        {

            saveImageInDataBase(1);

        }

        /// <summary>

        /// This is a required method which will save image in database.

        /// </summary>

        /// <param name="imageID"></param>

        public void saveImageInDataBase(int imageID)

        {

            byte[] imageData = ReadImageFile(textBox1.Text);    //This nethod returns image in byte array format.

            SqlConnection con = new SqlConnection();

            con.ConnectionString = "Data Source=aaaa;User ID=sa;Password=abcd;Initial Catalog=Workbook";  //provide connection string of your server.

            con.Open();   //open connection to server.

            string query = "insert into ImageTable values(@imageId,@imageData)";     //create a query variable.

            SqlCommand cmd = new SqlCommand(query, con);          //create a sqlcommand object.

            cmd.Parameters.Add(new SqlParameter("@imageId", imageID));    //add first parameters.

            cmd.Parameters.Add(new SqlParameter("@imageData", imageData));    //add second parameters.

            int rows = cmd.ExecuteNonQuery();         //execute query.

            if (rows > 0)

                MessageBox.Show("Image saved.");

            else

                MessageBox.Show("Unable to save image.");

            con.Close();

        }

        /// <summary>

        /// This method will converts image in byte array format and returns to its caller.

        /// use System.IO namespace regarding streaming concept.

        /// </summary>

        /// <param name="imageLocation"></param>

        /// <returns></returns>

        public byte[] ReadImageFile(string imageLocation)

        {

            byte[] imageData = null;

            FileInfo fileInfo = new FileInfo(imageLocation);

            long imageFileLength = fileInfo.Length;

            FileStream fs = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);

            BinaryReader br = new BinaryReader(fs);

            imageData = br.ReadBytes((int)imageFileLength);

            return imageData;

        }

    }

Tuesday, December 5, 2017

Enhancing the power of SharePoint Foundation Search with Microsoft Search Server Express

Problem

SharePoint Foundation 2010 is a great FREE product from Microsoft which often fulfils many businesses needs. However, in my opinion, what lets us down is the Search functionality. Businesses expect and want more out of Search but aren't always prepared to deploy Microsoft SharePoint Server, which includes more a powerful Search functionality.

Solution

The solution is quick, easy and FREE! Installing Microsoft Search Server Express 2010 within your SharePoint farm will give you the following search connectors:

  • SharePoint sites
  • Windows file shares
  • Exchange public folders
  • Lotus Notes
  • Web sites
  • IFilters for additional repositories
  • Structured content in databases
  • Federation object model

The two most common ones are the ability to search your current SharePoint install and a Windows file server share at the same time.

Installation

The following deployment steps and screen shots are taken from a single server SharePoint Foundation 2010 environment, running on Windows Server 2008.

1. On your SharePoint 2010 Foundation server, install Microsoft Search server 2010 (download here)

2. After the installation is complete the Configuration Wizard will appear, just like the SharePoint installation.

3. Select "No, do not create a default site" this is because you already have a SharePoint site.

4. The Configuration Wizard will now continue through 11 steps.

5. Note task 10 can take a while to complete but there is a additional percentage complete indicator.

6. Once the Configuration Wizard has finished you will receive the Configuration Successful message. Note you are also informed you need to access SharePoint Central Administration to finish the installation.

Configuration

1. Open SharePoint Central Administration and browse to Services on Server, click the new "SharePoint Server Search"

2. Click the Search Service Application to configure the new search service

3. Note the Default Content access account, you will need to change this if you want to crawl file shares, to an account which has permission to read the files. Also note the crawl will be in progress.

4. Browse to your SharePoint web application and create a new site.

5. On the new site form enter the following making sure you select the "Basic Search Center" option from the new Enterprise tab in the Template Selection section.

6. Once the new site creation wizard has completed you should be able to browse to your newly created Search Center

7. Enter a word in the search box and hit return to test the new search service. Note the refinement area shown below.

 

Installing SharePoint Foundation 2010 – Step by Step

We are always fall in problem to install SharePoint 2010 for the first time. Here is the step by step approach to install SharePoint 2010. This article is very much handy to install SharePoint Foundation 2010. Installation of other version of SharePoint is almost same. Here I have installed Windows 2008 Server in VMWare Workstation with 4GB of RAM. Below is the step by step approach to install SharePoint 2010.

Step 1: Install Windows 2008 Server R2

Step 2: Configure Windows Server 2008 R2 to install SharePoint 2010

Step 3: Create Domain Controller

Step 4: Install SQL Server – 2008 R2

Step 5: Install Prerequisites

There are two ways to install prerequisite –

i)        First way – Download the following prerequisites according to your Server Requirements and install it's to the server. Keep in mind, some are already installed in your computer so don't worry about installation problem. May be all prerequisite is not necessary for your server.
a.  Windows 2008 R2 and Windows Server 2008 KB971831
b. WCF Fix article for Windows 2008 R2 and Windows 7 KB976462
c. Microsoft SQL Server 2008 Native Client
d. Microsoft "Geneva" Framework Runtime
e. Microsoft Sync Framework Runtime v1.0 (x64)
f. Microsoft Chart Controls for Microsoft .NET Framework 3.5
g. Microsoft SQL Server 2008 Analysis Services ADOMD.NET
h. PowerShell V2 RTM
i. SQL Server 2008 SP1
j. .NET Framework 3.5 Service Pack 1 (Full Package)
k. Microsoft Filter Pack x64 for sharepoint

ii)       Second way – This is the very easy way. Just click executable file (SharePointFoundation.exe). Click "Install software prerequisite" of the screen.

1

Click "Next" to start installation of pre requisites

1-1

Mark for license Agreement and Click Next

1-2Pre requisites is installing.

1-3

Click Finish to complete installation of Pre requisites.

1-4

Step 6: Start SharePoint 2010 Foundation installation – Click Executable file (SharePointFoundation.exe). Click "Install SharePoint Foundation" in the splash screen.

2

Step 7: Mark to the license agreement and click Continue.

3

Step – 8: Browse data location and Click "Install Now"

4Installation Progress…

5

Step 9: Mark "Run the SharePoint Product Configuration Wizard now" and click "Close".

6

Step 10: Click "Next" of the SharePoint Products Configuration Wizard.

7

Step 11: Click "Yes" of the following pop up screen and then click "Next".

8

Step 12: Select "Create a new server farm" and then click "Next" of the following screen.

9

Step -13: Type your database server name, database Name (default: SharePoint_Config), user name (domain name\User name) and password in the following Database Settings screen.

10

Step 14: Type Passphrase and confirm passphrase in the Farm Security Settings screen and click "Next"

11

Step 15: To specify port of Central administration we application – Mark specify port number and type your desired port. Select NTLM as default as authentication provider for Web application.

12

Step 16: Click "Next" in following SharePoint Product Configuration Wizard. If required click Advanced Settings for advanced configuration

13

Configuring SharePoint Products…..

14Step 17: You will see the following screen after configuring SharePoint Server successfully. Necessary information is given here. Click "Finish" to continue.

15

Step 18: Type username (my user name: Administrator) and password to enter the server.

16

Step 19: Select "No, I don't wish to participate" and click "ok" in the following screen.

17

Step – 20: Click "Start the Wizard" in the following screen.

18

Step -21: Select "Use existing managed account" and click "Next"

19Processing…

20Step -22: Type site title and description, select template as Team site and click Ok.

21

Step – 23: Farm configuration completed. Click "Finish" in the Farm Configuration wizard.

22

Step – 24: Now you will see the central administration. If you see in the closer look, you will see it uses port -2010(read circle) which you configured at step – 15.

23

Step – 25: If you want to see the site which you already created just type "htttp://yourservername:80" in the url.

24Yes! You have successfully installed and configured SharePoint 2010. Thanks for your patience.

Friday, December 1, 2017

AUTHENTICATION IN ASP.NET

Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against some authority. If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity. Once an identity has been authenticated, the authorization process determines whether that identity has access to a given resource.

In ASP.Net, it provide the three types authentication Provider
  1.    Window Authentication Provider
  2.    Form Based Authentication Provider
  3.    Passport Based Authentication 
Window Authentication Provider:

Windows Authentication is the default authentication mechanism for ASP.NET applications and is identified as the authentication mode for an application using the authentication configuration element

In this Authentication, we set the window mode in web.config as 

<system.web>
<authentication mode="Windows"/>
</system.web>
Form Based Authentication:

Forms authentication enables you to authenticate the user name and password of your users using a login form that you create. Unauthenticated requests are redirected to a login page, where the user provides credentials and submits the form.

How make the form based authentication

Step1: Firstly we set into web config file

<system.web>
<authentication mode="Forms"/>
</system.web>
Then we add the path of login page and give the name
<system.web> 
<authentication mode="Forms">
 <forms LoginUrl ="Default.aspx"name="pzqw"></forms>
</authentication>
</system.web>

Note: LoginUrl and name both are element of authentication. In LoginUrl, Logon.aspx is the URL to use for redirection if ASP.NET does not find an authentication cookie with the request. And name show the user value store in cookies.

Then we add the authorization for deny users
<system.web> 
<authentication mode="Forms">
 <forms LoginUrl="Default.aspx"name="pzqw"></forms>
</authentication>
<authorization>
      <deny users="?"/>
    </authorization>
</system.web>

  Save it and cancel 

Passport Based Authentication

In Passport Based Authentication, the user because it is no longer necessary to log on to access new protected resources or sites. If you want your site to be compatible with Passport authentication and authorization, this is the provider you should use.We set the authentication mode in web config is Passport

Authentication is used for security purpose how we secure our site with outside user or invalid user.