Tuesday, June 3, 2014
File Upload and Download File from IIS Server.
Create a site for those files in IIS.
Design the form as follows.
cs Page
Web.config
<addkey="TemplateUploadPath"value="\\ABC-DTTR\Templates\"/>
<addkey="PDFDownloadPath"value="http://localhost:8089/"/>
<addkey="PDFDownloadPhysicalPath"value="\\ ABC-DTTR\Templates \"/>
Now, I want to download the upload file.
GetDownloadPage.aspx
.cs Page
In page load
stringstrTemplatePath = "mvc-routes.pdf";
stringstrTable = "";
strTable = "<table border='0' width='100%'>";
strTable = strTable + "<tr>";
strTable = strTable + "<td style='width:5%'>";
strTable = strTable + "<imgsrc='images/images.jpg' />";
strTable = strTable + "</td>";
strTable = strTable + "<td style='width:10%'>";
strTable = strTable + "<a href='GetFile.aspx?Filepath=" + strTemplatePath + "'>Download</a>";
strTable = strTable + "</td>";
strTable = strTable + "<td style='width:80%'>";
strTable = strTable + "<a href='#' onclick='javascript:window.open(\"" + System.Configuration.ConfigurationManager.AppSettings.Get("PDFDownloadPath") + strTemplatePath + "\")'>" + strTemplatePath.ToString() + "</a>";
strTable = strTable + "</td>";
strTable = strTable + "</tr>";
strTable = strTable + "</table>";
divTable.InnerHtml = strTable;
GetFile.aspx
OUTPUT:
Friday, May 30, 2014
CROSS Page Posting in ASP.NET
Postback and Cross Page Posting
If(Page.IsPostBack==true)
Ispostback->
When the page is loaded for the first time it is false, when the page is loaded again then it is true.
Example
If (Ispostback) ->
If true then it goes inside that loop
If (! ispostback) ->
If false then it goes inside that loop. We write this line in page load in most of the application.
Cross Page PostBack is which is used to submit one Page(Default.aspx) controls to another page(Default2.aspx) and access Default.aspx control values in Another Page(Default2.aspx)
Example
Cross page posting is submitting the form to a different page. This is usually required when you are creating a multi-page form to collect information from the user on each page. When moving from the source to the target page, the values of controls in the source page can be accessed in the target page.
Design the Form as
Default2.aspx
Default2.aspx.cs
Go to Default3.aspx
Default3.aspx.cs
Difference between Server. Transfer and Cross Page Posting
In ‘Server.Transfer’, the URL doesn't change whereas in cross page posting, the form is submitted to a different page, thereby changing the url.
The Server.Transfer method is a server-based operation whereas cross-page postback is a client-based transfer.
By using Master Page
ContentPlaceHolder pageContent =
(ContentPlaceHolder)
(Page.PreviousPage.Form.FindControl ("Content1"));
TextBox1.Text = pageContent.FindControl("button1");
To avoid casting the control type, you can also access the previous page data(Default2.aspx) by creating public properties that expose the data that you need to access.
In Default2.aspx
public String BTarget
{
get
{
return button1.Text;
}
}
In the ‘Default3.aspx’, access the value of the Button using the exposed property
Label1.Text = PreviousPage.BTarget;
MVC Basic Example
File->New Project->Select the template
ASP.NET MVC4 Web Application
Select the type of Template
And Click On OK Button
Now I want to create a page without using Master Page.
Master page is located at the following location
By default one master page is created, so now I want to create a page without using that default master page or any other master page which is created by you.
Now go to controller
And right click on Controller and Select Add Controller and Give the name as Default Controller.
And Click on Add Button
By default one Method is created for Every Controller.
So every controller by default has this Method Index (). So whenever we run this Controller by Default Index Method will Gets Executed. So now I want to create my own method and run that method by Default.
So now I have created my Own Method that Is Default Index (). So now the controller is ready. So we have to create a View for this Controller.
So go to Controller and Right click on Selected Method Name i.e. (Default Index)
And select Add View
And Click on Add Button
By default the same Name is used for View Also. (I.e. Default Index)
DefaultIndex.cs.html
So now the View is created without using the Master Page.
Now I want to Run, the View. So Go to RouteConfig
And set the Controller Name and the Method Name, so that when we run the Application by Default this View is displayed (this is similar to Set as Start Page in aspx)
Now Run the Application and See the output
Subscribe to:
Posts (Atom)
Kubernetes
Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...
-
Super aggregates: Are used to calculate aggregates of aggregates There are two super aggregates functions Roll Up Cube When there is a singl...
-
SOLID principles allows object oriented programming implementation in an efficient better way into project development S-->Single R...
-
With this example you can create pdf and print pdf. If You are using ASP.NET MVC , PDF can be created by using Rotativa Rotativa is a ...