Wednesday, October 28, 2015

Calculated Columns in SharePoint List/Library

SharePoint Calculated Columns are powerful tools when creating out-of-the-box solutions.With these columns, we can manipulate other columns in the list item.
Below is basic example to update list item based on other column.Lets get started

Scenario: 


Lets Create a document library named "Shared Document" ,Business Owner have assigned to review document in Library.We will create 3 additional columns in library(one-Date Time Column and two-Calculated column).

           Column  Name       Data Type

          ------------                          -------------
          Yearly review Date Time

          Review Complete                 Calculated Column


          Review Not Complete           Calculated Column



 If Documents "Yearly review" is done then "Review Complete" should be filled with "Yes" and "Review Not Complete" should be empty


 If Documents "Yearly review" is not done then "Review Not Complete" should be filled        with "Yes" and "Review Complete" should be empty.

Follow below steps to create and add formula to library/list
    


Step 1 : Create Document Library 


Step 2 : Create Date Data Type Column named "Yearly Review" 


Step 3 : Create Calculated Column "Review Complete" with below formula

         
            Formula:  =IF(ISBLANK([Yearly Review]),"","YES")

Step 4 : Create Calculated Column "Review Not Complete" with below formula

         
             Formula:  =IF(ISBLANK([Yearly Review]),"YES","")

Step 5 : Add a document and observe the "Review Complete"  and "Review Not Complete" Columns.Below is sample screenshot for above scenario.



Thanks for Reading :)               

        


Tuesday, July 14, 2015

SharePoint Excel File Upload : System.Data.OleDb.OleDbException: Unspecified error at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)

Hello,

When your writing SharePoint Custom solutions for file upload or importing excel file data into SharePoint list.If you get the below error.

"System.Data.OleDb.OleDbException: Unspecified error
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()"

Solution:

Go to Web.Config file of your SharePoint Web Application application.The location of web.Config File is looks like this .C:\inetpub\wwwroot\wss\VirtualDirectories\80\web.config. My Web application port number is 80 so I am navigating to above Folder. Check you Web Application port number and navigate to Web.Config file folder.

Then Open Web.Config File and Find The below Tags as shown below.By default Impersonate will be set to true so you neeed to change it to false as shown in below screen shot:


More about Impersonation:

Impersonation, a feature that was added in Windows SharePoint Services 3.0, enables you to perform actions on behalf of another user. Impersonation is useful in scenarios such as timer operations that need to update something asynchronously on behalf of a user long after the user has stopped using the Web site (that is, when their workflow is completed).

Thanks for Reading!
Hope Your Issue Resolved!

Regards,
Kiny :)
  




Friday, July 10, 2015

SharePoint File Upload : The Microsoft Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.

Hello,

I have faced same Issue when uploading excel file into SharePoint list:

Problem: 

Before resolving this issue,I was directly browsing the excel file from local system.When i click on upload button, I keep on getting Error "The Microsoft Access database engine cannot open or write to the file ''.  It is already opened exclusively by another user, or you need permission to view and write its data "

I was reading excel file using file upload control as shown below:

         if (!uploadfile.HasFile)
            {
                ltrlMsg.Text = "Please select a valid Excel File";
                return;
            }
            try
            {

                 //reading file from file upload control.

                 string fileName = uploadfile.PostedFile.FileName;

                //Some code goes here
            }
             catch (Exception Ex1)
               {
                            ltrlMsg.Text = Ex1.Message;

                 }

For Reference:


Solution: 

Then am storing excel file in root directory then reading file path from root directory using file upload control as as shown below:

Create New Folder in Root directory of SharePoint Web application as shown in below screen shot.
Example: I have created a folder named "GnIExcelFiles" in root path.

Root Path: C:\inetpub\wwwroot\wss\VirtualDirectories\41417

Here 41417 is port no of my Share Point web application in , check which is the port number of your web application and create new folder as described.


Then Change the code  as shown below:


string uploadexcelfile = Path.GetFileName(uploadfile.PostedFile.FileName); uploadfile.PostedFile.SaveAs(Server.MapPath("~/GnIExcelFiles/") + uploadexcelfile);
string fileName = Server.MapPath("~/GnIExcelFiles/") + uploadexcelfile;

For Reference:



I resolved my issue using above small piece of Code :)
Give A try , It will work

Thanks for Reading !

Kiny!



               






Friday, May 29, 2015

Check Box Checked and Un-Checked Events in Data Grid Header

             
In this article we will see how Check Box check and uncheck event works in Data Grid Header. In this article I have created the database using first code approach and the main aim of this article is to explain how to place check box in data grid header and when a header checkbox is checked then all the cells of that column will be in checked state and when header check box is un-checked the all the cells of that column should un-checked state. The below calm code will explain how to place check box in data grid header and cell of that particular column 

<Data Grid AutoGenerateColumns="False" Height="270" CanUserAddRows="False"     Name="dataGrid1" VerticalAlignment="Top" Width="481" >
   <DataGrid.Columns>
    <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"  Width="50"/>
     <DataGridTextColumn Header="Price" Binding="{Binding Path=Price}" Width="50" />
        <DataGridTextColumn Header="Unit" Binding="{Binding Path=Unit}" Width="50"/>
          <DataGridTemplateColumn>
             <DataGridTemplateColumn.Header>
<CheckBox Content="Uncheck All Or Check All" Checked="CheckBox_Checked"    Unchecked="CheckBox_Unchecked"/>

                    </DataGridTemplateColumn.Header>


                    <DataGridTemplateColumn.CellTemplate>
                     <DataTemplate>
                     <CheckBox Name="chkDiscontinue" IsChecked="{Binding values,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"  />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>


There are two events which take place in Data Grid Header namely checked event and unchecked event. I will explain both events one by one as shown below:
1: Check Box Checked Event in Data Grid Header Select Column:
In this event when you check the check box in Data grid Header Select column then all the check box present in cells of that column will be in checked state. See the below snapshot






The code behind for Check Box Checked Event in Data Grid Header Column Select is
private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            Database DB = new Database();
            Products products = new Products();
            foreach (var r in DB.prod)
            {
                r.values = true;
            }
            DB.SaveChanges();
            dataGrid1.ItemsSource = DB.prod.ToList();
           
        }

Check Box Un-Checked Event in Data Grid Header Select Column:
In this event when you un-check the check box in Data grid header select column then all the check box present in cells of that select column will be in un-checked state. See the below snapshot


The code behind for Check Box Un-Checked Event in Data Grid Header Column is
private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            Database DB = new Database();
            Products products = new Products();
            foreach (var r in DB.prod)
            {
                r.values = false;
            }
            DB.SaveChanges();
            dataGrid1.ItemsSource = DB.prod.ToList();
        }


Summary:
In this article I have explained how check box events works data grid header. I have also uploaded the source code. If you have any doubts please do comment. Thank you for reading my article

Source Code: Download






Edit and Delete Operation in DataGrid Using Context Menu, Pop Up Window


In this article we will see how to edit and delete a selected item(selected row) in Data Grid. In
this article I have used Code-First approach to create database of an employee .Using Load
button I am loading an employee details into Data Grid as shown in below snapshot.



Using Context Menu For Edit and Delete Operation:

In a Data Grid, to edit or delete a particular row right click on the selected row then a context
menu will appears on the Data Grid . I have created a context menu for Data Grid, when you right click on Data Grid a context menuwill appear for edit and delete options. The following is the Xaml Code for Context Menu inData Grid.

Xaml Code for Creating Context Menu on Data Grid:
<DataGridName="dataGrid1"Height="186Width="412"
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Edit" Click="Edit_Click">
<MenuItem.Icon>
<Image Name="Edit" Source="edit.png" Height="20" Width="20"></Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="Delete" Click="Delete_Click">
<MenuItem.Icon>
<Image Name="Delete" Source="delete.png" Height="20" Width="20"></Image>
</MenuItem.Icon>
</MenuItem>
</ContextMenu>
</DataGrid.ContextM
</DataGrid>
When you right click on the selected row in a Data Grid the context menu will appears. The
below snapshot will show how context menu will looks in Data grid.



Edit Operation:

When you click on the Edit, the selected item details of Data grid will get added to the Pop up
window.You can Edit Data then click Ok to update the data.
This is the code behind for edit click:
privatevoid Edit_Click(object sender, RoutedEventArgs e)
{
popup.IsOpen = true; //Pop up window will open
Database DB = newDatabase();
Employee emp = newEmployee();
int pid = ((Employee)dataGrid1.SelectedItem).Id;
var query = (from t in DB.employees
where t.Id == pid
select t).First();
txtName.Text = query.Name;
txtAge.Text = query.Age.ToString();
txtGender.Text = query.Gender;
txtMobile.Text = query.MobileNo.ToString();
txtAddress.Text = query.Address;
}
The below snapshot show how pop up window looks when you click on edit menu item


Delete Operation:
When you click delete option then selected row from Datagrid will be deleted from the database.
This is the code behind for delete menu item.
privatevoid Delete_Click(object sender, RoutedEventArgs e)
{
Employee emp = newEmployee();
Database DB = newDatabase();
int pid = ((Employee)dataGrid1.SelectedItem).Id;
var query = (from t in DB.employees
where t.Id == pid
select t).First();
DB.employees.Remove(query);
DB.SaveChanges();
MessageBox.Show("Selected Row Deleted Successfully ");
dataGrid1.ItemsSource = DB.employees.ToList();
}

Summary:
In this article I have showed how to create a context menu for Data grid using that we have seen
how edit and delete operation can be performed. If you have any queries please do comment.

Thank you for reading my article.

Source Code: Download


Storing and Retrieving Text File From SQL Server Database in WPF


In this article we will see how to store Text File into Database and Retrieve Text File from the Database. In this article I will show how to store text file into database in the form of array of bytes and retrieving array of bytes into text file from the database. Now we will look into the System requirements.

System Requirements:
·         Microsoft Visual Studio 2010.
·         SQL Server 2008 R2.
First, we will look into design part first, the below snapshot shows the design of application.

In this article I have used the code first approach to create the database .I have taken only one class named Text Data as shown below:
  public class TextData
    {
        public int Id { get; set; }
        public string FilePath { get; set; }
        public byte[] TextToByte { get; set;}   
    }
In the above class Id property is the primary key, File Path property will take the path of file from system which you will browse and TextToByte property will store the text contents from text file in the form of array of bytes.

Procedure:
There are totally three button events are occurring namely browse event, store file event and retrieve file event as shown in above first snapshot. We will see the working of all three events one by one.

1: Browse Button Event:

When you click on browse button an Open Dialog Box will open to select the text file, the path of text file will be copied into text box. The code behind for browse button as shown below.

      private void Browse_Click(object sender, RoutedEventArgs e)
        {
            Database DB=new Database();
            TextData exam=new TextData();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog1.DefaultExt = ".txt";
            txtFilePath.Text = openFileDialog1.FileName;
        }
In the above code I am creating an object for open dialog class (Namespace is Microsoft.Win32), then I am calling show dialog method of Open dialog Class.Open dialog box is as shown in below snapshot.

After Selecting Text File, When you click on open button the system path of text file is stored in text box as shown in below snapshot.


2: Store Button Event:
After selecting the text file when you click on store file button, the text file contents will be stored into database in the form of array of bytes. Code behind for store file event is shown below.

private void Store_Click(object sender, RoutedEventArgs e)
        {
            Database DB = new Database();
            TextData exam = new TextData();
            exam.FilePath = txtFilePath.Text;
            exam.TextToByte = File.ReadAllBytes(txtFilePath.Text);
            DB.TextFile.Add(exam);
            DB.SaveChanges();
        }
The below snapshot shows how text file contents converted into array of bytes and the database details



3:Retrieve Button Event:
When you click on the retrieve button, the text file contents stored in Database in the form of array of bytes again encoded into text using below code.
private void Retrieve_Click(object sender, RoutedEventArgs e)
        {  
             Database DB = new Database();
            TextData exam = new TextData();
            var result = (from t in DB.TextFile
                          where t.FilePath==txtFilePath.Text
                          select t.TextToByte).FirstOrDefault();

            var   ss = System.Text.Encoding.Default.GetString(result);
            richTextBox1.AppendText(ss);
      
   } 

The encoded text file contents will be added to the rich text box using above code of retrieve button event. The below snapshot shows file contents in a rich text box.


Summary:
In this article I have shown how to store text file into database in the form of array of bytes and again retrieving array of bytes into text form. If you any queries please do comment and thank you for reading my article.

Source Code :Download





POP UP Window in WPF


In this article we will see how to use a Popup Window in WPF. The Popup control displays
content in a separate window that floats over the current application window. The following
snapshot shows a Popupcontrol that is positioned with respect to a buttonthat is its parent.



What Is a Popup Window ?
A Popup control displays content in a separate window relative to an element or point on the
screen. When the Popup is visible, the Is Openproperty is set to true.

The following Xaml Code Will Create a Popup Window and button will acts as its parent:
<Button Content="Click Me forLogin!!" Click="Login Click"/>
<Popup Name="popup"Is Open="False" Placement="Mouse">
<BorderBorder Brush="Black" BorderThickness="1" Background="Coral">
<StackPanel Orientation="Horizontal">
<Image Source="/WPF.png" Height="100"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="User Name" Grid.Row="0" Grid.Column="0"/>
<TextBox Grid.Row="0" Grid.Column="1" Name="txtName" />
<TextBlock Text="Password" Grid.Row="1" Grid.Column="0"/>
<PasswordBox Grid.Row="1" Grid.Column="1" Name="txtPwd" />
<Button Content="OK" Grid.Row="2" Grid.Column="1" Click="PopUp_OK_Click"/>
</Grid>
</StackPanel>
</Border>
</Popup>
What are Controls that implement Popup ?
You can build Popup controls into other controls. The following controls implement
the Popup control for specific uses:
· Tool Tip
· Context Menu
· Expander
· Combo Box
How to Close and Open aPopup ?
Open a Popup: The Popup Control displays its contents when IsOpen set true.
privatevoid Popup_Ok_Click(object sender, RoutedEventArgs e)
{
Popup1.IsOpen = true;
}
where popup1 is the name of the popup control
Closing a Popup: The Popup Control displays its contents when IsOpen set false.
privatevoid Popup_Ok_Click(object sender, RoutedEventArgs e)
{
Popup1.IsOpen = false;
}
where popup1 is the name of the popup control
How to set placement behavior of Popup?
To customize the placement of Popup use the placement property of a
Popup control and there are various options in customizing the placement of a Popup such as
custom, right, left, mouse etc.
EX: Placement=”Mouse”
Summary:
In this article I showed how to use Popup control in WPF. If you have any question regarding
improvement of this article please do comment. Thank you for reading my article :)

Source Code:Download