Posted by ken zheng on February 24, 2009
I was working on a way to close an InfoPath form using C# or VB.NET from the form code-behind after the user submits the form. The steps below help in running some custom code to save the data and then close the form.
Here are the steps to close the Form
* Set the Submit Action[Tools->Submit Options] within InfoPath for the form to “Perform custom action using Code” . Click the Edit Code option to submit the form using code
* Set the After Submit option under Advanced to “Close the Form”
Click the Edit Code button next to the perform custom action to submit the data. Editing the code adds an handler for the Form Submit event and a FormEvents_Submit method is created in the code behind. Once the code completes the submission, set the CancelableArgs.Cancel property of the SubmitEventArgs to false.
Here is a sample FormEvents Submit method
In the SubmitConnection method, I retrieve the required data connection and call the execute method for submission
Dim fileSubmit as FileSubmitConnection = CType(Me.Connections(”SharePoint Save”),Microsoft.Office.InfoPath.FileSubmitConnection)
fileSubmit.Execute()
In the above sample, the data connection that I want to use for Submit is named “SharePoint Save”. I typecast it as a FileSubmitConnection.
I found this solution on one of the forum posts
http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=2605818&SiteID=17
Posted in Sharepoint | Tagged: InfoPath | 1 Comment »
Posted by ken zheng on February 17, 2009
It is a bit of pain to create Custom Web Serivce. To test it, you cannot add it as web reference in the first place.
So what I did is reference the local web service first which will generate right classes. Then set the url in the code
ws.Url = “http://…/_vti_bin/CSR/CSRWebService.asmx”;
Posted in Uncategorized | 1 Comment »
Posted by ken zheng on February 11, 2009
1. the aspx code
<asp:GridView id="gv" runat="server" OnRowEditing="gv_RowEditing" OnPageIndexChanging="gv_PageIndexChanging" OnSorting="gv_Sorting" >
2. the code behind
public String gvSortDirection
{
get { return ViewState["SortDirection"] as String ?? "ASC"; }
set { ViewState["SortDirection"] = value; }
}
public String gvSortExpression
{
get { return ViewState["SortExpression"] as String ?? ""; }
set { ViewState["SortExpression"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
DataTable dataTable = new DataTable();
// fill datatable with data
gv.DataSource = GetSortedData(datatable, gvSortExpression, gvSortDirection);
gv.DataBind();
}
protected void gvUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gv = (GridView)sender;
DataView dv = gv.DataSource as DataView;
DataTable dataTable = dv.Table;
gv.DataSource = GetSortedData(dataTable, gvSortExpression, gvSortDirection);
gv.PageIndex = e.NewPageIndex;
gv.DataBind();
}
protected void gvUsers_Sorting(object sender, GridViewSortEventArgs e)
{
GridView gv = (GridView)sender;
DataView dv = gv.DataSource as DataView;
DataTable dataTable = dv.Table;
String sortdir = "";
if (e.SortExpression != "" & e.SortExpression != null)
{
if (gvSortExpression == e.SortExpression)
gvSortDirection = GetSortDirection();
else
gvSortDirection = "ASC";
gvSortExpression = e.SortExpression;
gvUsers.EditIndex = -1;
}
gv.DataSource = GetSortedData(dataTable, e.SortExpression, gvSortDirection);
gv.DataBind();
}
private String GetSortDirection()
{
String newSortDirection = String.Empty;
switch (gvSortDirection)
{
case "DESC":
newSortDirection = "ASC";
break;
case "ASC":
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
private DataView GetSortedData(DataTable dataTable, String SortExpression, String SortDirection)
{
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
if (SortExpression != "" && SortExpression != null)
dataView.Sort = SortExpression + " " + SortDirection;
// Add filter - You may add filter here
return dataView;
}
return null;
}
protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView gv = (GridView)sender;
DataView dv = gv.DataSource as DataView;
DataTable dataTable = dv.Table;
gv.DataSource = GetSortedData(dataTable, gvSortExpression, gvSortDirection);
gv.EditIndex = e.NewEditIndex;
gv.DataBind();
}
Posted in .Net | 4 Comments »
Posted by ken zheng on February 11, 2009
Sometimes, we will have requirements to access codebehind variable in ASPX page. It can be done by the following syntax.
The codebehind variable should be public variable to access in ASPX page.
ASPX
CodeBehind
public partial class _Default : System.Web.UI.Page
{
public string Name = "ASP.Net";
Calling CodeBehind Method in ASPX
CodeBehind
public DataTable GetAllRoles()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("SP_GetAllRoles", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataTable dt = new DataTable();
ada.Fill(dt);
return dt;
}
ASPX
<asp:DropDownList ID="ddlRoles" DataSource=''
DataTextField="Role" DataValueField="RoleID"
runat="server">
<a href=''>
Posted in Uncategorized | Leave a Comment »
Posted by ken zheng on February 6, 2009
Issue
User get’s a listed below error when opening a new or existing InfoPath form because of an error in the form’s code
Error
“The required version of the Microsoft .NET Framework is not installed on your computer or the InfoPath Primary Interop Assembly (PIA) is not registered. Use Add or Remove Programs in Control Panel to make sure that the required version of the Microsoft .NET Framework is installed. Or install it using Windows Update and run the Setup program again to confirm that the corresponding version of the .NET Programmability Support is installed, or contact your system administrator.”
Cause\Resolution
As the error message suggests either the Microsoft .NET Framework or the InfoPath Primary Interop Assembly (PIA) is not installed. If Microsoft .NET framework is not present on the system then this will need to be installed. If the user does not have the .NET Framework already installed (when installing Office 2007) then PIAs will not be installed. Additionally, the option to install the PIAs doesn’t show up in the Custom setup for Office. If the user does a complete install of Office 2007, then PIAs will get installed into the GAC automatically. It’s strongly recommended that a complete install of Office 2007 be performed.
If .Net Framework is installed after installing Office 2007, then PIA does not get installed automatically and this can to be installed by following the steps listed below
1. Go to ‘Add or Remove Programs…’
2. Select the Microsoft Office 2007 installation and click on change.
3. Select “Add or remove features” and click Continue.
4. Expand the “Microsoft Office InfoPath” and “.NET Programmability Support” node. Add the ‘.NET programmability support’. To add, right click on the node and select “Run from my computer”. Press continue and follow the on screen instructions to complete the setup.
Posted in Sharepoint | Tagged: InfoPath | Leave a Comment »
Posted by ken zheng on February 5, 2009
User always want to have a search function for current site, so I use the JQuery to hide the drop down list. First allow your Context Drop down and set it default to this site.
Then add this Javascript, just replace the id
$("#ctl00_m_g_6320b784_9efb_43c3_a98c_e579abb4311b_SBScopesDDL").css({display:'none'});
Posted in Sharepoint | Tagged: jQuery | Leave a Comment »
Posted by ken zheng on February 5, 2009
In short, you attach the backup database, create a web application with the content database of ‘DELETE_ME’, then after the web application is created, change the content database association though Central Administration (CA->Application Management->Content Databases), remove the “DELETE_ME” One (and delete from SQL Server) and then attach the restored one to the web application.
Posted in Sharepoint | Leave a Comment »
Posted by ken zheng on February 4, 2009
I went off to lunch and upon my return, noticed this message appearing in a bunch of places:
Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.
I blamed the client (not realizing as yet that it was my fault at this point) but eventually noticed that visual studio intellisense was warning me that I had malformed XSL. I corrected it and everything started working.
Be darned careful when working with ItemStyle.xsl (and any of the global XSL files) — breaking them affects many artifacts in the site collection.
Posted in Uncategorized | Leave a Comment »
Posted by ken zheng on February 4, 2009
Below is the JQuery Script to replace the first link of Global Breadcrumbs and you can replace text as well
<script type="text/javascript">
$(document).ready(function(){
//To replace the Global Breadcrumbs
$("#ctl00_PlaceHolderGlobalNavigation_PlaceHolderGlobalNavigationSiteMap_GlobalNavigationSiteMap").children(":first").children(":first").attr("innerText","SimCentral");
$("#ctl00_PlaceHolderGlobalNavigation_PlaceHolderGlobalNavigationSiteMap_GlobalNavigationSiteMap").children(":first").children(":first").attr("href","http://hotmail.com");
//To hide the Global Breadcrumbs
//$("#ctl00_PlaceHolderGlobalNavigation_PlaceHolderGlobalNavigationSiteMap_GlobalNavigationSiteMap").css({display:'none'});
});
</script>
Posted in Sharepoint | Tagged: jQuery | 1 Comment »
Posted by ken zheng on February 3, 2009
Today I ran into an access denied error when trying to create a page within a SharePoint publishing site. I was able to create web part pages and sites, but unable to create publishing pages despite being a site owner. After doing some searching I found some posts about users with similar errors. Come to find out, to create a publishing page, you need at least read rights to the master page gallery. I opened up the master page gallery in my site collection, and sure enough, it wasn’t inheriting site permissions and my user had no permissions on the master page gallery. I gave my user (the site owner group) read rights on the master page gallery and it took care of my problem. I can now create my publishing page!
Posted in Sharepoint | Leave a Comment »