Here in this article, we will discuss how to open one Exceltemplate in Asp.net.
You can also check my previous posts on:
Difference between web application and web site in Asp.Net
Permanently Redirect a Page in Asp.Net
Create and use User Control in Asp.Net
We have a requirement in our project that we have a link named as "ExcelTemplates",If you click this link one exceltemplate will open.
Under our project solution, we have a folder named as "TestDataTemplateExcel",which contains the excel template named as "TestTemplate.xlsx".
So what we did is we added a button in the .aspx page and in the .aspx.cs file in the button click event we called the below method.
private void GetTemplate()
{
//Get the application Path including the last \ and and truncate update to application root //folder.
string executablePath1 = Environment.CommandLine.Substring(1, Environment.CommandLine.IndexOf("\\bin"));
// Append the Excel template folder file path from root folder onwards.
executablePath1 = executablePath1 + "TestDataTemplateExcel\\TestTemplate.xlsx";
System.Diagnostics.Process.Start(executablePath1);
}
Description:
string executablePath1 = Environment.CommandLine.Substring(1, Environment.CommandLine.IndexOf("\\bin"));
The above line of code will get the application Path including the last \ and and truncate update to application root folder.
executablePath1 = executablePath1 + "TestDataTemplateExcel\\TestTemplate.xlsx";
This line of code will append the Excel template folder file path from root folder onwards.
System.Diagnostics.Process.Start(executablePath1);
System.Diagnostics.Process.Start will process and start the respective excel from the specified path.
You can also check my previous posts on:
Difference between web application and web site in Asp.Net
Permanently Redirect a Page in Asp.Net
Create and use User Control in Asp.Net
We have a requirement in our project that we have a link named as "ExcelTemplates",If you click this link one exceltemplate will open.
Under our project solution, we have a folder named as "TestDataTemplateExcel",which contains the excel template named as "TestTemplate.xlsx".
So what we did is we added a button in the .aspx page and in the .aspx.cs file in the button click event we called the below method.
private void GetTemplate()
{
//Get the application Path including the last \ and and truncate update to application root //folder.
string executablePath1 = Environment.CommandLine.Substring(1, Environment.CommandLine.IndexOf("\\bin"));
// Append the Excel template folder file path from root folder onwards.
executablePath1 = executablePath1 + "TestDataTemplateExcel\\TestTemplate.xlsx";
System.Diagnostics.Process.Start(executablePath1);
}
Description:
string executablePath1 = Environment.CommandLine.Substring(1, Environment.CommandLine.IndexOf("\\bin"));
The above line of code will get the application Path including the last \ and and truncate update to application root folder.
executablePath1 = executablePath1 + "TestDataTemplateExcel\\TestTemplate.xlsx";
This line of code will append the Excel template folder file path from root folder onwards.
System.Diagnostics.Process.Start(executablePath1);
System.Diagnostics.Process.Start will process and start the respective excel from the specified path.