Friday, July 13, 2012

Tab Control in Asp.Net



Scenerio:

I need your help in designing tab control in asp.net.My requirement is I need a tab control in asp.net(C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc.......
like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.
 
Example:Employee master
tab1:Employee name.........his name in the tab
tab2:Age.............his age
tab3:Address........his address
 
Solution:
 
You can do this using a simple div

<style type="text/css">

.tabs
        {
            position: relative;
            height: 20px;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
        .tabs li
        {
            display: inline;
        }
        .tabs a
        {
            height: 16px;
            background: #c2ceda;
            position: relative;
            padding: 8px;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a.tab-visited
        {
            background-color: #6898d0;
            border-right: 1px solid #fff;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a:hover
        {
            background-color: #80A0C6;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a.tab-active
        {
            background-color: #6898d0;
            border-right: 1px solid #fff;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
</style>
          
<div id="menuTabs">
                <ul id="tabs">
                    <li id="tab1">
                       <a href="#" onclick="javascript:showPanel1()">
                       <asp:Label ID="empName"></asp:Label>
                       </a>
                    </li>
                    <li id="tab2">
                        <a href="#" onclick="javascript:showPane2()">
                        <asp:Label ID="empAge"></asp:Label>
                        </a>
                   </li>
                </ul>
</div>
<div id="pane1"></div>



<div id="pane2" style="display:'none'"></div>



 
 
 
 
 
 
 
 
 
Now bind the table columns to each label
 
If you use Ajax Tab control if it contains long elapsed methods to invok asynchronously then exception throws. Rather using Ajax Tab control better use infragestic or simple div based tabs.

Tab Control in Asp.Net



Scenerio:

I need your help in designing tab control in asp.net.My requirement is I need a tab control in asp.net(C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc.......
like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.
 
Example:Employee master
tab1:Employee name.........his name in the tab
tab2:Age.............his age
tab3:Address........his address
 
Solution:
 
You can do this using a simple div

<style type="text/css">

.tabs
        {
            position: relative;
            height: 20px;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
        .tabs li
        {
            display: inline;
        }
        .tabs a
        {
            height: 16px;
            background: #c2ceda;
            position: relative;
            padding: 8px;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a.tab-visited
        {
            background-color: #6898d0;
            border-right: 1px solid #fff;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a:hover
        {
            background-color: #80A0C6;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
        .tabs a.tab-active
        {
            background-color: #6898d0;
            border-right: 1px solid #fff;
            font-size: 11px;
            font-weight: bold;
            color: #fff;
            font-family: Verdana, arial, helvetica, sans-serif;
            text-decoration: none;
        }
</style>
          
<div id="menuTabs">
                <ul id="tabs">
                    <li id="tab1">
                       <a href="#" onclick="javascript:showPanel1()">
                       <asp:Label ID="empName"></asp:Label>
                       </a>
                    </li>
                    <li id="tab2">
                        <a href="#" onclick="javascript:showPane2()">
                        <asp:Label ID="empAge"></asp:Label>
                        </a>
                   </li>
                </ul>
</div>
<div id="pane1"></div>



<div id="pane2" style="display:'none'"></div>


 
Now bind the table columns to each label
 
If you use Ajax Tab control if it contains long elapsed methods to invok asynchronously then exception throws. Rather using Ajax Tab control better use infragestic or simple div based tabs.

Sending SMS Code in C#.Net



 
Please find below code for sending SMS
/// <summary>
        /// Sends SMS
        /// </summary>
        /// <returns> Returns true if SMS sent successfully </returns>

  private bool SendSMS()
        {
            try
            {
                if (string.IsNullOrEmpty(txtSMSPhoneNumber.Text.Trim()))
                {
                    MessageBox.Show("Please enter Phone Number to send SMS""SMS Validation",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);

                    txtSMSPhoneNumber.Focus();
                    return false;
                }
                if (txtSMSPhoneNumber.Text.Trim().Length < 10)
                {
                    MessageBox.Show("Invalid Phone Number. Please enter valid Phone Number""SMS Validation",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);

                    txtSMSPhoneNumber.Focus();
                    return false;
                }
                if (string.IsNullOrEmpty(txtSMSText.Text.Trim()))
                {
                    MessageBox.Show("Please text to SMS""SMS Validation",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);

                    txtSMSText.Focus();
                    return false;
                }

                string SMSText = txtSMSText.Text.Trim().Replace(" """);
                StringBuilder SMSURL = new StringBuilder();
                SMSURL.Append("http://smsoutbox.info/?user=Abm&password=abm567&PhoneNumber=91");
                SMSURL.Append(txtSMSPhoneNumber.Text.Trim());
                SMSURL.Append("&Text=");
                SMSURL.Append(SMSText);
                SMSURL.Append("&Sender=Minacs");

                //ProcessStartInfo PSInfo = new ProcessStartInfo("http://www.google.co.in/");
                //PSInfo.WindowStyle = ProcessWindowStyle.Minimized;
                //PSInfo.CreateNoWindow = true;
                //Process.Start(PSInfo);

                Process.Start(SMSURL.ToString());

                ShowWaiting("Sending SMS");
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("Error in Function TestCustInfo.SendSMS. Error Message :- "
                    + ex.Message, ex);
            }
        }

Thursday, July 12, 2012

How to play flash video in SharePoint?



Flash movie files are mostly in two formats: SWF files and FLV files. 
 
FLV files are simply a container movie file, and in order to present them to the user in a manner in which they will be able to control the playback of the movie you need to wrap them in an SWF playback control. Embedding flash video into a SharePoint site isn’t that much different than doing it in any other site. The only challenge is figuring out where and how the required files will be hosted and made accessible by the SharePoint site and its users.
 
Assuming you already have an FLV file, if not there are several converter applications available that will create FLV files out of common video formats.
 
The next step is to find an FLV player that will present the video on our site. There are several third party FLV players available, many for free although some require licensing for commercial use. I’ve listed some here:
Each player has their own way of embedding, in this example I will use JW player. They have a neat tool on their site that you can use to generate the code needed to embed your video.
The player does require several files to be hosted and made readable by the user who will have access to the videos. You can create a dedicated document library and upload the appropriate files included in the FLV players package and then use the absolute URL in your embed code to reference them.

NOTE: Be sure that the users who will be watching the video have read access on the document library the FLV player files are stored in.

You then create a content editor web part in which you want the video to appear in and place the embedding code in the source editor.

Steps:

1. Create a document library called ‘Media’. Also create a folder called ‘Player‘ so we keep flash player files separate from video files in Media library.
 
 
 
2. Upload flash player files into Player folder. Those files are:
  • player.swf (Flash player wrapping the video)
  • preview.jpg (Preview image. Once you click on it, video will start playing)
  • swfobject.js (JavaScript file controlling player and video)
3. Upload your video FLV file in media libraryIn this demo, i use a sample video file named as myvideo.flv.
 
4. So far we are hosting player files and video files. Now go to page you want to put your video and insert a Content Editor Web Part. (Site Actions > Edit Page > Add a Web Part > Miscellaneous > Content Editor Web Part)
 
This web part will be displaying flash player and video.
 
5. Now edit this web part and open source editor.
 
6. Then insert following code into source editor window.
 
<script type=’text/javascript’ src=’Media/Player/swfobject.js’></script>
<div id=’mediaspace’>This text will be replaced</div>
<script type=’text/javascript’>
  var so = new SWFObject(‘Media/Player/player.swf’,'ply’,’550′,’403′,’9′,’#000000′);
  so.addParam(‘allowfullscreen’,'true’);
  so.addParam(‘allowscriptaccess’,'always’);
  so.addParam(‘wmode’,'opaque’);
  so.addVariable(‘file’,’http://YourSPSiteCollectionUrlGoesHere/Media/video.flv’);
  so.addVariable(‘image’,‘http://YourSPSiteCollectionUrlGoesHere/Media/Player/preview.jpg’);
  so.write(‘mediaspace’);
</script>
 
Note: Don’t forget to replace url of image and file variables with your own ‘mysite’ web url.
 
7. That’s all. If you have done everything without a mistake, you should be seeing your flash video as follows
 
 
You can download flash player and sample video files Here

Sandboxed Solutions and Form Solutions in Sharepoint 2010



SandBox Solutions 
Although SharePoint enables end users to customize their SharePoint sites to a certain degree, some customizations can only be made by deploying custom code and custom assets to the server via a solution. However, only a farm administrator has the ability to deploy a solution to the farm. In some cases, farm administrators don ’ t have the available time to deploy solutions in a timely manner, leaving end users frustrated that their solutions are not being

deployed as quickly as they would like. Furthermore, if a solution is deployed globally, particular features could become available to all site collections across the farm. This could be undesirable, especially in environments with hundreds or thousands of site collections, and especially in hosted environments in which one site - collection owner should be unaware of any activity in any other site collection on the server.

 
What Are Sandboxed Solutions?

SharePoint 2010 has introduced the concept of sandboxed solutions. A sandboxed solution is one  that can be uploaded to a specifi c site collection by a site - collection administrator using a browser.

By providing this functionality, site administrators are no longer required to wait for their farm administrator to deploy their solution because they can do it themselves. In addition, sandboxed solutions are applied only to the site collection to which they have been uploaded. 

No other site collection has any knowledge of the solution ’ s existence, just as another site collection would not be aware that a document had been uploaded to a document library in another site collection.

As great an idea as this might seem, because solutions deployed this way are not required to go through a thorough vetting process this approach could cause havoc in a farm for several reasons:

A single solution deployed to a single site collection could potentially consume so many server resources that it bogs down the entire server. Because the farm administrator isn ’ t necessarily aware of the sandboxed solution ’ s existence (it was uploaded without his knowledge), he would not immediately know why his server was performing slowly. It could potentially take some time to fi gure out the source of the problem.

A malicious or clumsy programmer could write code inside a solution that accesses objects in the farm, such as other site collections or even web applications. 

A sandboxed solution deployed without a farm administrator ’ s consent could potentially delete web applications and otherwise bring down the farm.
Microsoft has provided a solution to each of these problems:

Farm administrators can specify a threshold of server resources (a combined value that takes into account things like CPU and memory usage) that a site collection ’ s sandbox can use. 

Once that threshold has been met in a particular site collection, all the sandboxed solutions in that site will be turned off for the rest of day. (Clearly, this is a stop - gap measure to protect the server. The goal is for your solutions to not consume so many resources that they exceed that quota in a day.)

Sandboxed solutions do not run with full trust in the web application; instead, they run with a custom code access policy that grants them minimal permissions.

A limited API is available to sandboxed solutions, eliminating the ability for sandboxed solutions to access anything in the object model above the site collection (such as the web application or farm objects), or allowing code in sandboxed solutions to run with elevated privileges. 

Sandboxed solutions cannot deploy any files to the SharePoint root folder, and they cannot deploy objects such as site definitions and workflows.

Note: It is possible to get around some of the limitations of a sandboxed solution by writing a custom full trust proxy, then consuming that proxy using theSPUtility.ExecuteRegisteredProxyOperation method.

 
When a sandboxed solution is deployed, any features associated with it are automatically activated.


A Comparison of Farm and Sandboxed Solutions



FARM
SANDBOXED
Assemblies are placed in the GAC or in the Bin directory of a SharePoint web application.
Assemblies placed in the GAC are fully trusted, whereas assemblies placed in the bin directory of a web application can be partially trusted.
Assembly execution takes place in the webServer process (w3wp.exe).
Any assemblies associated with a solution are extracted, kept in memory, and executed within a special worker process called
SPUCWorkerProcess.exe.
This isolates the execution of sandboxed solutions from the
Operations of the underlying web process.
Solutions must be installed and deployed by a farm administrator
Solutions can be installed and  deployed by asite administrator
There are no limitations on which SharePoint classes and objects can be used in farm solution Assemblies.
Developers must leverage a subset of theSharePoint API when developing sandboxedSolutions.
Solutions will use however many server resources are necessary
Farm administrators have the ability to throttleThe server resources used by a given solution.



Sandboxed solutions are deployed to the Solution gallery in a given site collection. You can view the Solution gallery by navigating to the Site Settings page in the root site of the site collection, then clicking the Solutions link under the Galleries heading.


SandboxedSolutions.ps1 using Powershell


Add-SPUserSolution -LiteralPath C:\Solutions\MySolution.wsp

-Site http://sitename


Install-SPUserSolution -Identity MySolution.wsp

-Site http://sitename


Uninstall-SPUserSolution -Identity MySolution.wsp

-Site http://sitename


Remove-SPUserSolution -Identity MySolution.wsp

-Site http://sitename


Update-SPUserSolution -Identity MySolution.wsp

-Site http://sitename -ToSolution MySolutionV2.wsp

Get-SPUserSolution -Identity MySolution.wsp -Site http://sitename

Form Solutions

Farm solutions cannot be installed using a browser the way that sandboxed solutions can be.

Instead, PowerShell is needed. To install a farm solution, use the Install - SPSolution PowerShell command. This will add the solution to the solution store in Central Administration.To find the solution store, navigate to the Central Administration website and click the System Settings link in the navigation on the left side of the page. Under the heading Farm Management,click the link that says Manage Farm Solutions. This will take you to the Solution Management page.Clicking a solution in the list brings up a page for managing the solution properties. This page shows when and where the solution was deployed (if at all). In addition, the toolbar has buttons for deploying or retracting the solution. If the solution deploys globally, no confi guration is required beyond simply deploying the solution. Otherwise, the Deploy To? section will have a drop - down list containing the web applications in the farm. By selecting an item from the list, a user can select the web application to which the solution will be deployed. In the same way, the user can choose the web application from which the solution should be retracted, when applicable. Once a solution has been completely retracted from every location in the farm, it can be removed by clicking the Remove Solution button in the toolbar.As with sandboxed solutions, PowerShell can be used to add, deploy, retract, remove, and upgrade solutions.

Farm Solutions Using Powershell

Add-SPSolution -LiteralPath C:\Solutions\MySolution.wsp

Install-SPSolution -Identity MySolution.wsp -GACDeployment

Install-SPSolution -Identity MySolution.wsp

-WebApplication IntranetSite

Uninstall-SPSolution -Identity MySolution.wsp

Uninstall-SPSolution -Identity MySolution.wsp

-AllWebApplications

Remove-SPSolution -Identity MySolution.wsp

Update-SPSolution -Identity MySolution.wsp

-LitearlPath C:\Solutions\MySolutionV2.wsp -GACDeployment

Get-SPSolution -Identity MySolution.wsp

-Identity MySolution.wsp -Site http://sitename

How to Display Parent Site Document Library in a Subsite (Sharepoint)



Using the DataViewWebPart (DVWP) in SP Designer 2007. It can even be used to show data from other subsites. Below are some notes I made for myself.

Data View – Display content from one site on another site


Data View - Filter Data


1.   Create the appropriate Data View by following the steps in the Data View – Display content from one site on another site
 
2.   Click the Data View and then click the arrow in the upper-right corner to show the Common Data View Tasks list
 
3.     Click Filter in the Common Data View Tasks list
 
4.      Click here to add a new clause in the Filter Criteria dialog box
 
5.     Click Field Name box and then click the field that contains the values that you want
 
6.     Click Comparison box and then click the operator that you want (ex. Contains, Equals, etc.)
 
7.     Click Value box and then type or select the criteria that you want
 
9.     Click OK
 

1.     Open the page in SharePoint Designer

a.     Open the site where you want to display the list

b.    Copy the URL

c.     Open SharePoint Designer

d.    Click File and click Open Site...

e.     Paste the URL in the Site name: field and remove the file identifier (ex.pravahaminfo.com/Environment/default.aspx – delete the default.aspx)

f.     Click Open

g.    Double click on the appropriate page in the Folder list (lower left-hand pane)

2.     Insert Data View

a.     Click where you want the list to go on the page

b.    Click Data View

c.     Click Insert Data View (you can then drag and drop the web part if you want to move it around)

3.     Assign Data Source

a.     Open the site where you want to pull the list

b.    Copy the URL

c.     In SharePoint Designer, click Connect to another library... at the very bottom of the Data Source Library Task Pane

d.    Click Add

e.     Type the Display name:

f.     Paste the URL in the Location: (once again remove the file identifier)

g.    Click OK

h.     Click OK

i.      Click + to the left of the location you just added to the Data Source Library Task Pane to expand it (this may take a few seconds to finish)

j.      Click + to the type of file you want to connect to (ex. SharePoint Lists)

k.     Hover over the appropriate list and click the drop-down arrow

l.      Click Show Data

m.   Select the Rows you want to display by holding down the Ctrl key on your keyboard and clicking on the appropriate Row names

n.     Click Insert Selected Fields as... button

o.    Click Multiple Item View

p.    Save the page (click the X to close the page and click Yes and click Yes)