-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from assadvirgo/master
Aspose SiteFinity Widget to Export Users into Excel
- Loading branch information
Showing
8 changed files
with
464 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
...teFinity/Aspose.SiteFinity.ExportUsersToExcel/Aspose.SiteFinity.ExportUsersToExcel.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion> | ||
</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{FF856E44-A91C-49A3-BA85-D95FC29BD440}</ProjectGuid> | ||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Aspose.SiteFinity.ExportUsersToExcel</RootNamespace> | ||
<AssemblyName>Aspose.SiteFinity.ExportUsersToExcel</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<UseIISExpress>true</UseIISExpress> | ||
<IISExpressSSLPort /> | ||
<IISExpressAnonymousAuthentication /> | ||
<IISExpressWindowsAuthentication /> | ||
<IISExpressUseClassicPipelineMode /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>..\..\..\..\..\..\Program Files %28x86%29\Telerik\Sitefinity\Projects\Default\bin\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Aspose.Cells, Version=8.5.2.0, Culture=neutral, PublicKeyToken=716fcc553a201e56, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\..\..\..\..\wamp\www\aspose\dlls\Aspose.Cells.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Web.DynamicData" /> | ||
<Reference Include="System.Web.Entity" /> | ||
<Reference Include="System.Web.ApplicationServices" /> | ||
<Reference Include="System.ComponentModel.DataAnnotations" /> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Web.Extensions" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Web" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="System.Configuration" /> | ||
<Reference Include="System.Web.Services" /> | ||
<Reference Include="System.EnterpriseServices" /> | ||
<Reference Include="Telerik.OpenAccess"> | ||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Telerik\Sitefinity\Projects\Default\bin\Telerik.OpenAccess.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Telerik.Sitefinity"> | ||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Telerik\Sitefinity\Projects\Default\bin\Telerik.Sitefinity.dll</HintPath> | ||
</Reference> | ||
<Reference Include="Telerik.Sitefinity.Model"> | ||
<HintPath>..\..\..\..\..\..\Program Files (x86)\Telerik\Sitefinity\Projects\Default\bin\Telerik.Sitefinity.Model.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="AsposeExportUsersToExcel.ascx.cs"> | ||
<DependentUpon>AsposeExportUsersToExcel.ascx</DependentUpon> | ||
<SubType>ASPXCodeBehind</SubType> | ||
</Compile> | ||
<Compile Include="AsposeExportUsersToExcel.ascx.designer.cs"> | ||
<DependentUpon>AsposeExportUsersToExcel.ascx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="AsposeExportUsersToExcel.ascx" /> | ||
<Content Include="style.css" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" /> | ||
<ProjectExtensions> | ||
<VisualStudio> | ||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}"> | ||
<WebProjectProperties> | ||
<UseIIS>True</UseIIS> | ||
<AutoAssignPort>True</AutoAssignPort> | ||
<DevelopmentServerPort>56054</DevelopmentServerPort> | ||
<DevelopmentServerVPath>/</DevelopmentServerVPath> | ||
<IISUrl>http://localhost:56054/</IISUrl> | ||
<NTLMAuthentication>False</NTLMAuthentication> | ||
<UseCustomServer>False</UseCustomServer> | ||
<CustomServerUrl> | ||
</CustomServerUrl> | ||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> | ||
</WebProjectProperties> | ||
</FlavorProperties> | ||
</VisualStudio> | ||
</ProjectExtensions> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
22 changes: 22 additions & 0 deletions
22
.../SiteFinity/Aspose.SiteFinity.ExportUsersToExcel/Aspose.SiteFinity.ExportUsersToExcel.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.31101.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspose.SiteFinity.ExportUsersToExcel", "Aspose.SiteFinity.ExportUsersToExcel.csproj", "{FF856E44-A91C-49A3-BA85-D95FC29BD440}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FF856E44-A91C-49A3-BA85-D95FC29BD440}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FF856E44-A91C-49A3-BA85-D95FC29BD440}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FF856E44-A91C-49A3-BA85-D95FC29BD440}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FF856E44-A91C-49A3-BA85-D95FC29BD440}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
58 changes: 58 additions & 0 deletions
58
Plugins/SiteFinity/Aspose.SiteFinity.ExportUsersToExcel/AsposeExportUsersToExcel.ascx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AsposeExportUsersToExcel.ascx.cs" Inherits="Aspose.SiteFinity.ExportUsersToExcel.AsposeExportUsersToExcel" %> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"> | ||
<link rel="stylesheet" type="text/css" media="all" href="<%= ResolveUrl("~/Addons/Aspose.SiteFinity.ExportUsersToExcel/css/style.css") %>" /> | ||
<script type="text/javascript" language="javascript"> | ||
$(document).ready(function () { | ||
$('.selectAllCheckBox input[type="checkbox"]').click(function (event) { //on click | ||
if (this.checked) { // check select status | ||
$('.selectableCheckBox input[type="checkbox"]').each(function () { //loop through each checkbox | ||
this.checked = true; //select all checkboxes with class "checkbox1" | ||
}); | ||
} else { | ||
$('.selectableCheckBox input[type="checkbox"]').each(function () { //loop through each checkbox | ||
this.checked = false; //deselect all checkboxes with class "checkbox1" | ||
}); | ||
} | ||
}); | ||
}); | ||
</script> | ||
<h2 class="sub-header">Export Sitefinity Users to Excel</h2> | ||
<p id="NoRowSelectedErrorDiv" runat="server" visible="false" class="bg-danger error">Please select one or more users to export.</p> | ||
<div class="row"> | ||
<ul class="list-inline pull-right"> | ||
<li> | ||
<asp:DropDownList ID="ExportTypeDropDown" runat="server" CssClass="pull-right form-control"> | ||
<asp:ListItem Text="Excel Workbook (*.xlsx)" Selected="True" Value="xlsx"></asp:ListItem> | ||
<asp:ListItem Text="Excel Binary Workbook (*.xlsb)" Value="xlsb"></asp:ListItem> | ||
<asp:ListItem Text="Excel 97-2003 Workbook (*.xls)" Value="xls"></asp:ListItem> | ||
<asp:ListItem Text="Text (Tab delimited) (*.txt)" Value="txt"></asp:ListItem> | ||
<asp:ListItem Text="CSV (Comma delimited) (*.csv)" Value="csv"></asp:ListItem> | ||
<asp:ListItem Text="OpenDocument Spreadsheet (*.ods)" Value="ods"></asp:ListItem> | ||
</asp:DropDownList> | ||
</li> | ||
<li> | ||
<asp:Button ID="ExportButton" CssClass="btn btn-primary pull-right" runat="server" Text="Export" OnClick="ExportButton_Click"></asp:Button> | ||
</li> | ||
</ul> | ||
</div> | ||
<div class="row"> | ||
<asp:GridView ID="SitefinityUsersGridView" EmptyDataText="There are no users." Width="100%" EmptyDataRowStyle-CssClass="emptyClass" | ||
GridLines="None" BorderWidth="0" AutoGenerateColumns="false" | ||
CssClass="table table-striped" DataKeyNames="Email" ClientIDMode="Static" runat="server"> | ||
<Columns> | ||
<asp:TemplateField HeaderStyle-CssClass="rgHeader" HeaderStyle-Width="20px"> | ||
<HeaderTemplate> | ||
<asp:CheckBox ID="SelectAllCheckBox" CssClass="selectAllCheckBox" runat="server" /> | ||
</HeaderTemplate> | ||
<ItemTemplate> | ||
<asp:CheckBox ID="SelectedCheckBox" CssClass="selectableCheckBox" runat="server" /> | ||
</ItemTemplate> | ||
</asp:TemplateField> | ||
<asp:BoundField DataField="Username" HeaderText="Username" /> | ||
<asp:BoundField DataField="FirstName" HeaderText="Firstname" /> | ||
<asp:BoundField DataField="LastName" HeaderText="Lastname" /> | ||
<asp:BoundField DataField="Email" HeaderText="Email" /> | ||
</Columns> | ||
</asp:GridView> | ||
</div> |
176 changes: 176 additions & 0 deletions
176
Plugins/SiteFinity/Aspose.SiteFinity.ExportUsersToExcel/AsposeExportUsersToExcel.ascx.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
using Aspose.Cells; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.UI; | ||
using System.Web.UI.WebControls; | ||
using Telerik.Sitefinity.Security; | ||
using Telerik.Sitefinity.Security.Model; | ||
|
||
namespace Aspose.SiteFinity.ExportUsersToExcel | ||
{ | ||
public partial class AsposeExportUsersToExcel : System.Web.UI.UserControl | ||
{ | ||
protected void Page_Load(object sender, EventArgs e) | ||
{ | ||
UserManager userManager = UserManager.GetManager(); | ||
List<User> users = userManager.GetUsers().ToList(); | ||
|
||
DataTable output = new DataTable("ASA"); | ||
output.Columns.Add("LastName"); | ||
output.Columns.Add("FirstName"); | ||
output.Columns.Add("Email"); | ||
output.Columns.Add("Username"); | ||
output.Columns.Add("UserID"); | ||
|
||
|
||
foreach (User user in users) | ||
{ | ||
UserProfileManager profileManager = UserProfileManager.GetManager(); | ||
SitefinityProfile profile = profileManager.GetUserProfile<SitefinityProfile>(user); | ||
|
||
DataRow dr; | ||
dr = output.NewRow(); | ||
dr["FirstName"] = profile.FirstName; | ||
dr["Username"] = user.UserName; | ||
dr["Email"] = user.Email; | ||
dr["LastName"] = profile.LastName; | ||
dr["UserID"] = user.Id; | ||
|
||
output.Rows.Add(dr); | ||
|
||
|
||
} | ||
|
||
|
||
SitefinityUsersGridView.DataSource = output; | ||
//if (!IsPostBack) | ||
SitefinityUsersGridView.DataBind(); | ||
} | ||
|
||
private void ApplyCellStyle(ref Worksheet worksheet, string cellName) | ||
{ | ||
Cell cell = worksheet.Cells[cellName]; | ||
Aspose.Cells.Style style = cell.GetStyle(); | ||
style.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin; | ||
style.Borders[BorderType.TopBorder].Color = Color.Black; | ||
style.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin; | ||
style.Borders[BorderType.BottomBorder].Color = Color.Black; | ||
style.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin; | ||
style.Borders[BorderType.LeftBorder].Color = Color.Black; | ||
style.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin; | ||
style.Borders[BorderType.RightBorder].Color = Color.Black; | ||
|
||
style.Pattern = BackgroundType.Solid; | ||
style.ForegroundColor = Color.LightGray; | ||
|
||
style.Font.IsBold = true; | ||
cell.SetStyle(style); | ||
} | ||
|
||
private XlsSaveOptions GetSaveFormat(string format) | ||
{ | ||
XlsSaveOptions saveOption = new XlsSaveOptions(SaveFormat.Xlsx); | ||
|
||
switch (format) | ||
{ | ||
case "xlsx": | ||
saveOption = new XlsSaveOptions(SaveFormat.Xlsx); break; | ||
case "xlsb": | ||
saveOption = new XlsSaveOptions(SaveFormat.Xlsb); break; | ||
case "xls": | ||
saveOption = new XlsSaveOptions(SaveFormat.Excel97To2003); break; | ||
case "txt": | ||
saveOption = new XlsSaveOptions(SaveFormat.TabDelimited); break; | ||
case "csv": | ||
saveOption = new XlsSaveOptions(SaveFormat.CSV); break; | ||
case "ods": | ||
saveOption = new XlsSaveOptions(SaveFormat.ODS); break; | ||
} | ||
|
||
return saveOption; | ||
} | ||
|
||
protected void ExportButton_Click(object sender, EventArgs e) | ||
{ | ||
string format = ExportTypeDropDown.SelectedValue; | ||
|
||
DataTable selectedUsers = new DataTable("SU"); | ||
selectedUsers.Columns.Add("UserID"); | ||
selectedUsers.Columns.Add("DisplayName"); | ||
selectedUsers.Columns.Add("Email"); | ||
selectedUsers.Columns.Add("Username"); | ||
|
||
foreach (GridViewRow row in SitefinityUsersGridView.Rows) | ||
{ | ||
if (row.RowType == DataControlRowType.DataRow) | ||
{ | ||
CheckBox chkRow = (row.Cells[0].FindControl("SelectedCheckBox") as CheckBox); | ||
if (chkRow.Checked) | ||
{ | ||
string email = SitefinityUsersGridView.DataKeys[row.RowIndex].Value.ToString(); | ||
var userMan = UserManager.GetManager(); | ||
User user = userMan.GetUserByEmail(email); | ||
|
||
UserProfileManager profileManager = UserProfileManager.GetManager(); | ||
SitefinityProfile profile = profileManager.GetUserProfile<SitefinityProfile>(user); | ||
|
||
DataRow dr; | ||
dr = selectedUsers.NewRow(); | ||
dr["UserID"] = user.Id; | ||
dr["DisplayName"] = profile.FirstName + " " + profile.LastName; | ||
dr["Email"] = user.Email; | ||
dr["Username"] = user.UserName; | ||
selectedUsers.Rows.Add(dr); | ||
} | ||
} | ||
} | ||
|
||
if (selectedUsers.Rows.Count == 0) | ||
{ | ||
NoRowSelectedErrorDiv.Visible = true; | ||
} | ||
else | ||
{ | ||
// Check for license and apply if exists | ||
string licenseFile = Server.MapPath("~/App_Data/Aspose.Cells.lic"); | ||
if (File.Exists(licenseFile)) | ||
{ | ||
License license = new License(); | ||
license.SetLicense(licenseFile); | ||
} | ||
|
||
//Instantiate a new Workbook | ||
Workbook book = new Workbook(); | ||
//Clear all the worksheets | ||
book.Worksheets.Clear(); | ||
//Add a new Sheet "Data"; | ||
Worksheet sheet = book.Worksheets.Add("Sitefinity Users"); | ||
|
||
//We pick a few columns not all to import to the worksheet | ||
sheet.Cells.ImportDataTable(selectedUsers, true, "A1"); | ||
|
||
Worksheet worksheet = book.Worksheets[0]; | ||
|
||
ApplyCellStyle(ref worksheet, "A1"); | ||
ApplyCellStyle(ref worksheet, "B1"); | ||
ApplyCellStyle(ref worksheet, "C1"); | ||
ApplyCellStyle(ref worksheet, "D1"); | ||
|
||
worksheet.Cells.InsertRow(0); | ||
worksheet.Cells.InsertColumn(0); | ||
|
||
worksheet.AutoFitColumns(); | ||
|
||
string fileName = System.Guid.NewGuid().ToString() + "." + format; | ||
|
||
book.Save(this.Response, fileName, ContentDisposition.Attachment, GetSaveFormat(format)); | ||
Response.End(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.