1. Open a text document
2. Type the following lines
"echo Getting all SharePoint ports
pushd C:\Windows\System32\inetsrv
appcmd list wp
cd C:\Windows\System32\inetsrv
pause"
3. save as "myApps.cmd"
4. Run as Administrator
Saturday, October 22, 2011
Friday, October 21, 2011
SharePoint 2010 close the popup and redirect parent
In SharePoint 2010 we have popup windows in many places.
If we need to close the PopUp and redirect the parent to a new page or reload the PopUp we can use simple code :)
Server side Code In the POPUP page
string redirectUrl = ResourceWrapper.GetAAFResource("PopupMyApprovalsLink");
Response.Write("script type='text/javascript'>window.frameElement.navigateParent('"+ redirectUrl +"'));
also we can use,
Response.Write("script type='text/javascript'>window.frameElement.commitPopup()");
to close the PopUp
If we need to close the PopUp and redirect the parent to a new page or reload the PopUp we can use simple code :)
Server side Code In the POPUP page
string redirectUrl = ResourceWrapper.GetAAFResource("PopupMyApprovalsLink");
Response.Write("script type='text/javascript'>window.frameElement.navigateParent('"+ redirectUrl +"'));
also we can use,
Response.Write("script type='text/javascript'>window.frameElement.commitPopup()");
to close the PopUp
Thursday, October 6, 2011
Excel Macro To Send Emails Automatically
Option Explicit
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
Dim MyLimit As Date
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the MyLimit value it will run the macro
MyLimit = Date //Set The Current Date
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("J6:J60") //Date Range
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsDate(.Value) = False Then
MyMsg = "Not a date"
Else
If .Value < MyLimit Then
MyMsg = SentMsg
If .Offset(0, 1).Value = NotSentMsg Then
Call Mail_with_outlook2 //Call To Send Emails
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 1).Value = MyMsg
Application.EnableEvents = True
End With
Next FormulaCell
ExitMacro:
Exit Sub
EndMacro:
Application.EnableEvents = True
MsgBox "Some Error occurred." _
& vbLf & Err.Number _
& vbLf & Err.Description
End Sub
=================================================
Email Sending Part
=================================================
Sub Mail_with_outlook2()
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strto = Cells(FormulaCell.Row, "P").Value
strcc = ""
strbcc = ""
strsub = "Do an update"
strbody = "Hi " & Cells(FormulaCell.Row, "L").Value & vbNewLine & vbNewLine & _
"Your expiry date is: " & Cells(FormulaCell.Row, "J").Value & vbNewLine & _
"for the task of : " & Cells(FormulaCell.Row, "C").Value & _
vbNewLine & vbNewLine & "Do an update" & _
vbNewLine & vbNewLine & "Thanks." & _
vbNewLine & vbNewLine & "Regards," & _
vbNewLine & vbNewLine & "Marina Samaratunge"
With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
'You can add a file to the mail like this
'.Attachments.Add ("C:\test.txt")
.Display ' or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Private Sub Worksheet_Calculate()
Dim FormulaRange As Range
Dim NotSentMsg As String
Dim MyMsg As String
Dim SentMsg As String
Dim MyLimit As Date
NotSentMsg = "Not Sent"
SentMsg = "Sent"
'Above the MyLimit value it will run the macro
MyLimit = Date //Set The Current Date
'Set the range with Formulas that you want to check
Set FormulaRange = Me.Range("J6:J60") //Date Range
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
If IsDate(.Value) = False Then
MyMsg = "Not a date"
Else
If .Value < MyLimit Then
MyMsg = SentMsg
If .Offset(0, 1).Value = NotSentMsg Then
Call Mail_with_outlook2 //Call To Send Emails
End If
Else
MyMsg = NotSentMsg
End If
End If
Application.EnableEvents = False
.Offset(0, 1).Value = MyMsg
Application.EnableEvents = True
End With
Next FormulaCell
ExitMacro:
Exit Sub
EndMacro:
Application.EnableEvents = True
MsgBox "Some Error occurred." _
& vbLf & Err.Number _
& vbLf & Err.Description
End Sub
=================================================
Email Sending Part
=================================================
Sub Mail_with_outlook2()
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strto = Cells(FormulaCell.Row, "P").Value
strcc = ""
strbcc = ""
strsub = "Do an update"
strbody = "Hi " & Cells(FormulaCell.Row, "L").Value & vbNewLine & vbNewLine & _
"Your expiry date is: " & Cells(FormulaCell.Row, "J").Value & vbNewLine & _
"for the task of : " & Cells(FormulaCell.Row, "C").Value & _
vbNewLine & vbNewLine & "Do an update" & _
vbNewLine & vbNewLine & "Thanks." & _
vbNewLine & vbNewLine & "Regards," & _
vbNewLine & vbNewLine & "Marina Samaratunge"
With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
'You can add a file to the mail like this
'.Attachments.Add ("C:\test.txt")
.Display ' or use .Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Wednesday, September 14, 2011
SharePoint 2010 permission levels
Permission Levels
1. Full
2. High
3. WSS_Medium
4. Medium
5. Low
6. WSS_Minimal (Default security level that comes with SharePoint)
7. Minimal
Things that we can do when do custom development
1. Raise the trust level of the application
2. GAC your assemblies (so that they run in full trust and get the permissions needed)
3. Put the assemblies in to ‘Bin’ folder and create a custom policy file, refer it in web.config file
Create SharePoint search results using FullTextSqlQuery
DataTable search = new DataTable();
using (SPSite site = new SPSite(SPContext.Current.Web.Site.Url))
{
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue();
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue("Search Service Application");
FullTextSqlQuery query = new FullTextSqlQuery(searchProxy);
query.QueryText = "SELECT FirstName,LastName ,AccountName,WorkPhone,UserName,PreferredName,AboutMe,NationalityP,NationalityS FROM SCOPE() WHERE \"Scope\"='People' ";
query.ResultTypes = ResultType.RelevantResults;
query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.KeywordInclusion = KeywordInclusion.AllKeywords;
ResultTableCollection results = query.Execute();
if (results.Count > 0)
{
ResultTable relevant = results[ResultType.RelevantResults];
search.Load(relevant);
// serialize DataTable to XML
StringBuilder resultsXml = new StringBuilder();
using (StringWriter sw = new StringWriter(resultsXml))
{
search.WriteXml(sw);
sw.Flush();
}
// move XML to the XmlDataSource
XmlDataSource xds = new XmlDataSource();
xds.EnableCaching = false;
xds.Data = resultsXml.ToString();
}
}
using (SPSite site = new SPSite(SPContext.Current.Web.Site.Url))
{
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue
FullTextSqlQuery query = new FullTextSqlQuery(searchProxy);
query.QueryText = "SELECT FirstName,LastName ,AccountName,WorkPhone,UserName,PreferredName,AboutMe,NationalityP,NationalityS FROM SCOPE() WHERE \"Scope\"='People' ";
query.ResultTypes = ResultType.RelevantResults;
query.ResultsProvider = Microsoft.Office.Server.Search.Query.SearchProvider.Default;
query.KeywordInclusion = KeywordInclusion.AllKeywords;
ResultTableCollection results = query.Execute();
if (results.Count > 0)
{
ResultTable relevant = results[ResultType.RelevantResults];
search.Load(relevant);
// serialize DataTable to XML
StringBuilder resultsXml = new StringBuilder();
using (StringWriter sw = new StringWriter(resultsXml))
{
search.WriteXml(sw);
sw.Flush();
}
// move XML to the XmlDataSource
XmlDataSource xds = new XmlDataSource();
xds.EnableCaching = false;
xds.Data = resultsXml.ToString();
}
}
Create SharePoint search results programatically
private void ComplexSearch()
{
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue();
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue("Search_Service_CUSTOM");
KeywordQuery keywordQuery = new KeywordQuery(searchProxy);
string SearchScope = "PEOPLE";
keywordQuery.HiddenConstraints = "scope:" + "\"" + SearchScope + "\"";
keywordQuery.TrimDuplicates = true;
keywordQuery.EnableStemming = true;
keywordQuery.IgnoreAllNoiseQuery = true;
keywordQuery.QueryText = "SELECT AccountName,PreferredName,PictureUrl,WorkEmail,JobTitle,Department,InternalNumber,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,InternalTelephone,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,HitHighlightedProperties,CollapsingStatus,Path,FirstName,LastName FROM Scope() WHERE ('scope'='People')";
keywordQuery.EnablePhonetic = true;
keywordQuery.ResultsProvider = SearchProvider.Default;
keywordQuery.ResultTypes = ResultType.RelevantResults | ResultType.SpecialTermResults ;
ResultTableCollection resultsTableCollection = keywordQuery.Execute();
ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];
DataTable resultsDataTable = new DataTable();
resultsDataTable.TableName = "Results";
resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);
DataView view = new DataView(resultsDataTable);
SearchGrid.DataSource = resultsDataTable;
SearchGrid.DataBind();
}
{
SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue
SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue
KeywordQuery keywordQuery = new KeywordQuery(searchProxy);
string SearchScope = "PEOPLE";
keywordQuery.HiddenConstraints = "scope:" + "\"" + SearchScope + "\"";
keywordQuery.TrimDuplicates = true;
keywordQuery.EnableStemming = true;
keywordQuery.IgnoreAllNoiseQuery = true;
keywordQuery.QueryText = "SELECT AccountName,PreferredName,PictureUrl,WorkEmail,JobTitle,Department,InternalNumber,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,InternalTelephone,OfficeNumber,AboutMe,Responsibility,Skills,HitHighlightedSummary,HitHighlightedProperties,CollapsingStatus,Path,FirstName,LastName FROM Scope() WHERE ('scope'='People')";
keywordQuery.EnablePhonetic = true;
keywordQuery.ResultsProvider = SearchProvider.Default;
keywordQuery.ResultTypes = ResultType.RelevantResults | ResultType.SpecialTermResults ;
ResultTableCollection resultsTableCollection = keywordQuery.Execute();
ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];
DataTable resultsDataTable = new DataTable();
resultsDataTable.TableName = "Results";
resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);
DataView view = new DataView(resultsDataTable);
SearchGrid.DataSource = resultsDataTable;
SearchGrid.DataBind();
}
Wednesday, August 31, 2011
SharePoint Credential Popup disabling
It was a so much trouble to me when working SharePoint to give "Credentials" always. Even we are not thinking about it, it takes considerable amount of time. So i have decided to avoid from it.
Internet Explorer --> Internet Options --> Security --> Trusted Sites --> User authentication

Wednesday, August 17, 2011
How to Open a DataSet using Microsoft Excel in a web application
protected void btnExportExcel_Click(object sender, EventArgs e)
{
DataSet ds = CurrentApproverService.GetReportData(depID, UserID);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + "ReportData.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
dg = null;
dg.Dispose();
}
{
DataSet ds = CurrentApproverService.GetReportData(depID, UserID);
DataGrid dg = new DataGrid();
dg.DataSource = ds;
dg.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + "ReportData.xls");
Response.ContentType = "application/excel";
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
dg.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
dg = null;
dg.Dispose();
}
Monday, August 8, 2011
How SharePoint 2010 Installation creates SQL Sever DataBases
I was able to get step by step screen shots of,
SharePoint 2010 installation Vs. SQL Server DB creation
(1) Initial DB structure
SharePoint 2010 installation Vs. SQL Server DB creation
(1) Initial DB structure
(2) While SharePoint 2010 Installing
(3) Step 3 of "SharePoint 2010 product configuration" is the main step that creates "Config" database
(4) When "Configure SharePoint Farm" using Central Administration
(5) SQL DB structure while running wizard
(6) After Configured All Services in "SharePoint 2010"
It is Easy And Structured :)
Localization in SharePoint
It was a horrible week for me, because of a too critical task, i.e.LOCALIZATION
Finally i was able to do it :) :) :)
*** Added "ChanaApp.resx" to App_GlobalResources folder in [Port] folder
*** Added "ChanaApp.nl.resx" to same folder
*** Added a label to .ASPX page
*** Set the Expression of the label, set the TEXT property using "Resources"
*** If only one page we can use
protected override void InitializeCulture()
{
string[] languages = HttpContext.Current.Request.UserLanguages;
string language = languages[0].ToLowerInvariant().Trim();
string selectedLanguage = language;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
base.InitializeCulture();
}
*** If for total web application then we have to use
protected void Application_BeginRequest(object sender, EventArgs e)
{
string[] languages = HttpContext.Current.Request.UserLanguages;
string language = languages[0].ToLowerInvariant().Trim();
string selectedLanguage = language;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
in GLOBAL.ASAX file.
*** Change the Culture of browser will change the TEXT in the label
Finally i was able to do it :) :) :)
*** Added "ChanaApp.resx" to App_GlobalResources folder in [Port] folder
*** Added "ChanaApp.nl.resx" to same folder
*** Added a label to .ASPX page
*** Set the Expression of the label, set the TEXT property using "Resources"
*** If only one page we can use
protected override void InitializeCulture()
{
string[] languages = HttpContext.Current.Request.UserLanguages;
string language = languages[0].ToLowerInvariant().Trim();
string selectedLanguage = language;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
base.InitializeCulture();
}
*** If for total web application then we have to use
protected void Application_BeginRequest(object sender, EventArgs e)
{
string[] languages = HttpContext.Current.Request.UserLanguages;
string language = languages[0].ToLowerInvariant().Trim();
string selectedLanguage = language;
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(selectedLanguage);
Thread.CurrentThread.CurrentUICulture = new
CultureInfo(selectedLanguage);
}
in GLOBAL.ASAX file.
*** Change the Culture of browser will change the TEXT in the label
Subscribe to:
Posts (Atom)



