Generate excel sheet from classic asp on click of button - asp-classic

I want to create an excel sheet from click of button.
These excel sheet will contain report which is generated on classic asp page. When user clicks on button then an excel sheet should be created which will have the same report as page have

This header works fine:
<%
Response.AddHeader "Content-Disposition", "attachment;filename=NOMBRE_ARCHIVO.xls"
Response.ContentType = "application/vnd.ms-excel"
%>
For small tables, try this example in html/javascript:
<html>
<body>
<table id="tabla" border="1">
<tr><th>Uno</th><td>1</td></tr>
<tr><th>Dos</th><td>2</td></tr>
</table>
<p>
<input type="button" onclick="javascript:exportarExcel('tabla');" value="Vamos al excel!">
</p>
</body>
<script type="text/javascript">
function exportarExcel(tabla){
var t = document.getElementById(tabla);
t.border = 1;
var html = t.outerHTML;
html = encodeURIComponent(html);
// problemas con el encoding!
// se puede usar base64_encode() en lugar de encodeURIComponent(html))
// ojo con encodeURIComponet() que está deprecada. lo mejor sería usar base64
window.open('data:application/vnd.ms-excel,' + html);
}
</script>
</html>

Related

Data communication between two userInterface (ui) - Apps script refer to client instantiated sidebar

For the use of a google sheet stock management by several people, I use a sidebar for authentication (login). This running well, but i would like to allow different and simultaneous authentications (on different client computers)
In fact, my google scripts andZ html forms (integrated in userInterfaces) should be able to know and use the current agent, memorized by a sidebar field, as long as it is not closed.
I tried to use userProperties, scriptProperties, documentProperties,and cacheService but the connected agent is then memorized and common for all users instead of being specific to each workstation running the application. I have to work on the client side.
I know how to read and modify the DOM of the sidebar by the javascript code that i place there and also to recover this information within my google script. But here it is in fact a question of finding information from the instantiated sidebar.
My Apps Script:
function init_SideBar(e) { // init & show the sidebar
htmlSideBar = HtmlService.createHtmlOutputFromFile('htmlSideBar')
.setTitle('htmlSideBar')
.setWidth(300);
htmlSideBar.info="blabla"; // could it be a lead ?
SpreadsheetApp.getUi().showSidebar(htmlSideBar);
}
function gScriptFcGiveToSidebar() { // to send datas in an array to html page
let jSONforSheet= JSON.stringify(objForSheet);
return jSONforSheet;
}
function calledFromFormSubmit(sidebarForm) { // Receive datas from html sidebar
agentConnected=sidebarForm;
if(agentConnected=="Deconnecté"){
ss.toast("Deconnecté")
}else{
ss.toast("Bonjour "+agentConnected);
}
}
htmlSideBar.html:
<html>
<head>
<title>HTML DOM Objects</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>
<label for="dowloading">dowloading</label>
<script>
function submitForm() { // envoi les données du form "sidebarForm" vers la fonction qui dans google script va les récupérer
// login & password verification (tablUser contains a column au login and a column of mp)
var elmts=document.getElementById("sidebarForm");
for(let iUsers=0;iUsers<sidebarObj.tablUser.length;iUsers++){
if (sidebarObj.tablUser[iUsers][0]==elmts.agentId.value){
if(sidebarObj.tablUser[iUsers][1]==elmts.mpId.value ){
document.getElementById('labelConnectId').innerHTML =elmts.agentId.value;
google.script.run.calledFromFormSubmit(elmts.agentId.value);
return;
}
}
}
alert ("password false, try again");
}
function deconnect(){
document.getElementById('labelConnectId').innerHTML ="Deconnecté";
document.getElementById('agentId').value ="Deconnecté";
google.script.run.calledFromFormSubmit("Deconnecté");
}
function jsFcGiveToForm(jSONforSheet){ //
$('#rangeResult').text(jSONforSheet); //$('#rangeResult').text(<nom de la variable qui va finalement délivrer au js, les données du google script>)
sidebarObj=JSON.parse(jSONforSheet);
document.write('<label id="labelConnectId" form="sidebarForm" > '+sidebarObj.agentConnected+'</label>');
document.write('<br><input type="button" value="Deconnect" onclick="deconnect();" />');
document.write('<form id="sidebarForm">');
document.write('<select name="agent" id="agentId">');
document.write('<option value="'+sidebarObj.agentConnected+'">'+sidebarObj.agentConnected+'</option>');
for(let iUsers=0;iUsers<sidebarObj.tablUser.length;iUsers++){
document.write('<option value="'+sidebarObj.tablUser[iUsers][0]+'">'+sidebarObj.tablUser[iUsers][0]+'</option>');
}
document.write('</select>');
document.write('<br /><input type="text" name="mp" id="mpId" value="password">');
document.write('<br /><input type="button" value="Submit" onclick="submitForm();" />');
document.write('<input type="button" value="Close" onclick="google.script.host.close()" />');
}
document.close(); // HYPER IMPORTANT !! libere le navigateur pour qu il continu a charger la page
google.script.run.withSuccessHandler(jsFcGiveToForm).gScriptFcGiveToSidebar();
</script>
</form>
</body>
</html>
Some leads ? :
Must i use scriptless
<?= blablabla?>
Using Meta tags :
var x = document.createElement("META");
x.setAttribute("name", "description");
x.setAttribute("content", "blablabla");
document.head.appendChild(x);
Using a property of htmlOutpu:
htmlSideBar.info="blabla";
Thanks a lot for your participation ! :)
I found a solution and described the sequences using the commented steps A1-4 and B1-12) which you just have to follow
Sidebar.gs:
function init_SideBar(e) { //A-1) init & show the sidebar.html
htmlSideBar = HtmlService.createHtmlOutputFromFile('htmlSideBar')
.setTitle('htmlSideBar')
.setWidth(300);// n'est plus modifiable fixé par google à 300 px
htmlSideBar.info="blabla";
HtmlService.SandboxMode=HtmlService.XFrameOptionsMode;
SpreadsheetApp.getUi().showSidebar(htmlSideBar);
}
function gScriptFcGiveToSidebar() { // A-3) to send google sheet datas (array or json...) to htmlSideBar.html page
let jSONforSheet= JSON.stringify(objForSheet);
ss.toast("json"+jSONforSheet);
return jSONforSheet;
}
function gScriptFromSidebarThenGiveToFormIn(sidebarAgent,provenanceFlag){
//Browser.msgBox("2 4 sidebarAgent="+sidebarAgent+" cache="+cacheService.get('sidebarAgent')+"init="+init);
if (provenanceFlag==false) { // B-7) Called by the de html htmlFormIn...withSuccessHandler(jsFcGiveToFormIn)
// Utilities.sleep(8000); // simulating an excess of a retention time of the cache
sidebarAgent=cacheService.get('sidebarAgent'); // B-8) Retieve the useful data in the cache
if (sidebarAgent==null) {return "echec";} // B-9) Abort in case the cache got lost (retention time exceeded)
cacheService.remove('sidebarAgent'); // B-10) Free the cache
return sidebarAgent; //B-11) give to formIn.html the data it expects
}else{ // B-2) provenanceFlag=true means that the call is from the htmlSideBar.html file buton.onclick , (sidebarAgent has the useful data)
if (cacheService.get('sidebarAgent')!=null) return false // B-3) cache not freed, abort proces for try again in a few time
cacheService.put('sidebarAgent',sidebarAgent,5); // B-4) Stock in cache the data for 5 secondes
initFormIn(sidebarAgent); //B5 open the user interface formIn.html that will have to take imediately the data in the cache, then free it
}
}
function calledFromFormSubmit(sidebarForm) { // Receive datas from html sidebar
agentConnected=sidebarForm;
//userProperties.setProperty('agentConnected', agentConnected);
if(agentConnected=="Deconnecté"){
ss.toast("Deconnecté")
}else{
ss.toast("Bonjour "+agentConnected);
}
//SpreadsheetApp.getActiveSheet().appendRow(["test",sidebarForm]);
}
htmlSideBar.html:
<!DOCTYPE html>
<html>
<head>
<style>
body { font-size:1em; }
p { color : red; }
</style>
<title>HTML DOM Objects</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
</head>
<body>
<label for="dowloading">dowloading</label>
<?= info?>
<script>
function callFormIn(){ google.script.run.gScriptFromSidebarThenGiveToFormIn(document.getElementById("labelConnectId").innerHTML,true);
}
function submitForm() { // My connect process
var elmts=document.getElementById("sidebarForm");
for(let iUsers=0;iUsers<sidebarObj.tablUser.length;iUsers++){
if (sidebarObj.tablUser[iUsers][0]==elmts.agentId.value){
if(sidebarObj.tablUser[iUsers][1]==elmts.mpId.value ){
document.getElementById('labelConnectId').innerHTML =elmts.agentId.value;
google.script.run.calledFromFormSubmit(elmts.agentId.value);
return;
}
}
}
alert ("mp faux");
}
function writeLabelAndTxtBox(name,id,value){
document.write('<br /><label for="'+name+'">'+name+': </label>');
document.write('<br /><input type="text" name="'+name+'" id="'+id+'" value="'+value+'">');
}
function writeLabel(name){
document.write('<br /><label for="'+name+'">'+name+': </label>');
}
function writeTxtBox(name,id,value){
document.write('<br /><input type="text" name="'+name+'" id="'+id+'" value="'+value+'">');
}
// -----------------------------------------------------------------------------------------------------------------
function clearAndClose(){
google.script.host.close();
}
function deconnect(){
document.getElementById('labelConnectId').innerHTML ="Deconnecté";
document.getElementById('agentId').value ="Deconnecté"; // facultatif ?
google.script.run.calledFromFormSubmit("Deconnecté");
}
function jsFcGiveToSidebar(jSONforSheet){ // A-4) I can Fill the sidebar.html page with json datas received from apps script about goole sheet
// End of the A1-4) states
sidebarObj=JSON.parse(jSONforSheet); // in particular sidebarObj.tablUser[] that contains the sheet columns of logins and passwords
/* sidebarObj.agentConnected was used to don't have to connect when open a new sidebar
(I dont speak aubout the google acount connection)
sidebarObj.keepConnectPropertie==false desactive this mode
i prefer now have to connect on each new sidebar instentiation.
the login is preserved while the sidebar is instantiated.
*/
document.write(new Date().toLocaleDateString());
if (sidebarObj.keepConnectPropertie==false){sidebarObj.agentConnected="Deconnecté"}
document.write('<label id="labelConnectId" form="sidebarForm" > '+sidebarObj.agentConnected+'</label>');
document.write('<br><input type="button" value="Deconnect" onclick="deconnect();" />');
document.write('<form id="sidebarForm">');
document.write('<select name="agent" id="agentId">');
document.write('<option value="'+sidebarObj.agentConnected+'">'+sidebarObj.agentConnected+'</option>');
for(let iUsers=0;iUsers<sidebarObj.tablUser.length;iUsers++){
document.write('<option value="'+sidebarObj.tablUser[iUsers][0]+'">'+sidebarObj.tablUser[iUsers][0]+'</option>');
}
document.write('</select>');
writeTxtBox('mp','mpId','password')
document.write('<br><input type="button" value="Submit" onclick="submitForm();" />');
document.write('<br><input type="button" value="FormIn" onclick="callFormIn();" />'); // B-1) run gScriptFromSidebarThenGiveToFormIn() with data parameter needed
document.write('<input type="button" value="Close" onclick="google.script.host.close()" />');
}
document.close();
google.script.run.withSuccessHandler(jsFcGiveToSidebar).gScriptFcGiveToSidebar(); // A-2) give to jsFcGiveToSidebar() the return of gScriptFcGiveToSidebar()
</script>
</form>
</body>
</html>
htmlFormIn.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<style type="text/css">
.myDiv {cursor:pointer;}
.divBlack{background-color:#000; color:#fff;}
</style>
<label for="dowloading">dowloading</label>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
// ---------------------------------------------- Functions for Javascript ------------------
function writeLabel(name){
document.write('<br /><label for="'+name+'">'+name+': </label>');
}
function writeTxtBox(name,id,value,prefix){
prefix=prefix||'<br />';
document.write(prefix+'<input type="text" name="'+name+'" id="'+id+'" value="'+value+'">');
}
// -------------------------------------------------Wrinting in Body -----
function addRow(){
cptLine++;
//alert(sidebarAgent); // alert(document.getElementById("idLblSidebarAgent").innerHTML);
//document.getElementById("tableForm").appendChild("tr");
let newLin = document.getElementById("tableForm").insertRow(-1); // ajoute un <tr> à la fin de la table
let newCell=newLin.insertCell(0); // ajoute un <td>
newCell.innerHTML = '<input type="text" name="" id=c"'+cptLine+'" value="v'+cptLine+'"> <input type="text" name="" id=d"'+cptLine+'" value="'+sidebarAgent+'">';
//alert("ajouté");
}
function jsFcGiveToFormIn(aagent){ // B-12) aagent receive the data value return from gScriptFromSidebarThenGiveToFormIn that have been called in A6 state
// B-13) the formIn.html can fill its fields :) - End of the B1-12) states
if (aagent=="echec"){ alert ("htmlFormIn 71 le cache service n'a pas memorisé assez longemps le transfert de donnée depuis la sidebar")}
sidebarAgent=aagent; // pour étendre la portée de cette info dans le script de cette page html
document.write('<label id="idLblSidebarAgent" for="info">'+sidebarAgent+'</label>')
writeTxtBox("Saisie","idSaisie","Entrez un code");
document.getElementById("idSaisie").addEventListener("click", addRow);
document.write('<form id="sidebarForm">');
document.write('<table id="tableForm"><tr id="r'+cptLine+'""><td>');writeTxtBox("Date","iddat","date"," ");writeTxtBox("Ref","idRef"+cptLine,""," ");
writeTxtBox("agent","idAgent",sidebarAgent," ");
document.write('</td></tr>')
document.write('</table>')
document.write('</form>');
}
document.close();
var cptLine=0;
var sidebarAgent;
google.script.run.withSuccessHandler(jsFcGiveToFormIn).gScriptFromSidebarThenGiveToFormIn("",false); // B-6) give to jsFcGiveToFormIn the return of gScriptFromSidebarThenGiveToFormIn("",provenanceFlag=false) with provenanceFlag=false that meaning the call is from formIn.html file.
</script>
</body>
</html>

ADODB Stream: Download Text File Issues

I am in a situation where a stream connection is called when the user clicks a download button. When the download button is submitted, a function is called up in ASP, where the download code is executed on the file BD_Test1.txt. The contents of this text file are simply TEST 1.
The file downloads as normal, however when opening it, all of the HTML code is on the text file.
HTML Code
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
End If
%>
</body>
</html>
ASP Code
<%
Function downloadFile()
Dim download_File, download_Remove, download_Autoremove
Set download_File = Server.CreateObject("ADODB.Stream")
download_File.Type = 1
download_File.Open
download_File.LoadFromFile("E:\inetpub\wwwroot\cdc\wnyaccc_erie_niagara_trd-2\youkergav\BulkDownload\resumes\BD_Test1.txt")
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=Resumes.txt"
Response.CharSet = "UTF-8"
Response.ContentType = "text/plain"
Response.BinaryWrite download_File.Read
download_File.Close
Set download_File = Nothing
End Function
%>
Contents of Downloaded Text File
<html>
<head>
<title>Bulk Download Zipper</title>
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
TEST 1
</body>
</html>
As you can see, the contents of the text file are being inserted where the downloadFile() function is called. Is it possible to use a stream connection is this way?
Your downloadFile function is being called after the page has already begun getting served to the client. ASP is simply injecting the result of your function. You will need to override the entire output on POST. Output the html on GET, and output the text file on POST:
<%
If (Request.Form("zipFile") <> "") Then
Call downloadFile()
Else%>
<html>
<head>
<title>Bulk Download Zipper</title>
<!--#include file="BD_Download.asp"-->
</head>
<body>
<center><h1>Bulk Download Zipper</h1></center>
<br><br>
<p>Please click "Download" to zip the files.</p>
<form method="post">
<br><input type = "submit" name="zipFile" value = "Download"/><br>
</form>
<br><br>
</body>
</html>
<%
End If
%>

"***" Does not contain a definition for "pnlMenu"

Im trying to get info from my database into my html, and im almost there. but for some reason, when i tried something, it all went south, it doesnt want to grab anything, and i have no idea why. ill upload all of my code here. and yes, i know is messy.
ASPX
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="home" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title> Micha de Haan's Portfolio </title>
<link href="styles/main.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
</head>
<body>
<form id="form1" runat="server">
<!-- Alles tussen de header is de balk bovenin -->
<header>
<div class="ijzerenman"> </div>
<div class="verzekering"><img src="styles/Logo.png" Width:="60px" height="60px"></div>
<h1>
<strong>Welkom op mijn portfolio</strong>
</h1>
<ul>
<asp:Panel ID="pnlMenu" runat="server"></asp:Panel>
<%-- <div class="current1"><li>Home</li></div>
<div class="orange"><li>Over mij</li></div>
<div class="red"><li>Logboek</li></div>
<div class="green"><li>Ervaring</li></div>
<div class="blue"><li>Familie</li></div>
1-tabel aanmaken 'menu' met kolommen id, titel, pageid, kleur
2- daarna vullen met bovenstaande paginas
3 - alle records ophalen en doorlopen
4 -tijdens doorlopen stroing itemsoptellen
string strMenu += String.Format( #"<div class=\"{0}\"><li>{2}</li></div>", strKleur, strPageId, strTitle);
5- strMenu in literalcontrol
6 - toevoegen aan panel
--%>
</ul>
<%
string pageId = Request.QueryString["pageId"];
if (pageId == null || pageId == "") pageId = "start";
%>
</header>
</form>
</body>
</html>
ASPX.CS
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class home : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pageId = Request.QueryString["pageid"];
//Vraagt de QueryString aan die in de url wordt aangegeven
if (pageId == null) pageId = "start";
// als de pageid Querystring niets is, dan is de pageId "start"
string connectionString = ConfigurationManager.ConnectionStrings["dbCon"].ConnectionString;
//zet de connectiestring "dbCon", zodat de gebruiker bij aanpasbare informatie kan
SqlConnection con = new SqlConnection(connectionString);
//maakt een nieuwe instantie aan van een SqlConnection. dit is een representatie van een open verbinding aan SQL Databases.
SqlCommand cmd = new SqlCommand("select * from Menu", con);
//een command die wordt gestuurd naar de database, die vraagt om * te selecten van Menu, waar de * con is, en Menu de Menu database.
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd);
//Representeert een set van commands en een database connectie die worden gebruikt om een DataSet ( Een "cache" van data in het geheugen ) en om een SQL Database te updaten.
DataSet dataSet = new DataSet();
// een "cache" van data in het geheugen
dataAdapter.Fill(dataSet);
//refresht en updated de rijen in een database
DataTable table = dataSet.Tables[0];
// pakt de tabels in de dataset, en loopt constant tot er geen tables meer te krijgen zijn.
String content = "";
//zet string content naar niets
foreach (DataRow row in table.Rows)// Voor elke rij in table.rows (alle rijen in de table) pakt hij de kleur, pageId en Titel, en zet ze inplaats van de nummers.
{
content += string.Format(#"<div class=""{0}""><li>{2}</li></div>", row["Kleur"], row["PageId"], row["Titel"]);
}
this.pnlMenu.Controls.Add(new LiteralControl(content));//zet de resultaten van de content string in het html bestand, waar de pnlMenu wordt gerefrenced.
}
}
It looks like you are missing the namespace in code behind, in this snippet the myProject namespace. It should look like this
using System;
namespace myProject
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
That should also be present in the aspx file header Inherits property
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="myProject.WebForm1" %>
You probably deleted some stuff by accident. It would be easiest to create a new page and copy-paste all the code.

Export web page to pdf

I am having a web page in which there is a canvas js chart. When I generated a pdf, the only canvas js chart do not displayed in the pdf.
How can I solve this problem?
I previously had this issue, we ended up using: http://www.highcharts.com/ then exported to png -> http://www.highcharts.com/docs/export-module/export-module-overview.
After the svg-> png conversion we converted to PDF using standard libraries.
To export JS Chart into PDF, First you have to convert chart data into canvas image byte stream and then to PDF.
The following code will help you to convert JS Chart into PDF
In Aspx Page
<asp:HiddenField ID="hfImageData" runat="server" />
<div id="dvTable">
<div class="row">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="x_panel">
<div class="x_title"> Your chart data comes here <h2> SLA </h2>
</div>
<div class="x_content">
<canvas id="canvas000"></canvas>
</div>
</div>
</div>
</div>
</div>
<asp:Button ID="btnExport" runat="server" Text="Export to PDF" CssClass="btn btn-primary" onclick="btnExport_Click" OnClientClick="return ConvertToImage(this)" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.rawgit.com/niklasvh/html2canvas/master/dist/html2canvas.min.js"></script>
<script type="text/javascript">
function ConvertToImage(btnExport) {
html2canvas($("#dvTable")[0]).then(function (canvas) {
var base64 = canvas.toDataURL();
$("[id*=hfImageData]").val(base64);
__doPostBack(btnExport.name, "");
});
return false;
}
</script>
In Aspx.cs Page
protected void btnExport_Click(object sender, EventArgs e)
{
string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
string fileName = "Chart.pdf";
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(bytes);
using (MemoryStream memoryStream = new MemoryStream())
{
var pgSize = new iTextSharp.text.Rectangle(1600, 1000);
Document document = new Document(pgSize, 88f, 88f, 10f, 10f);
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
document.Open();
document.Add(image);
document.Close();
bytes = memoryStream.ToArray();
memoryStream.Close();
}
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
whatever data present under div id "dvTable" will be converted to PDF when we click on Export
PhantomJS sounds like an option for you, take a look at the NReco wrapper for using it with .Net https://www.nrecosite.com/phantomjs_wrapper_net.aspx

Display a PDF file from FTP server inside an ASPX page C#

I have a PDF file on my FTP Server. I want to display the PDF file using ASP.Net.
I used google viewer in an iframe control:
<iframe src="http://docs.google.com/gview?url=ftp://samplepdf.com/sample.pdf" style="width:718px; height:700px;" frameborder="0"></iframe>
It worked perfectly while viewing pdfs from public servers. The problem is that I need to give ftp username and password for the pdf to be displayed on my asp.net page.
Any thoughts?
Thanks in advance
Edit:
I can use
url=ftp://username:pass#ftp.samplesite.com/...
but I dont want the username and password to be attached to the url.
I also tried this code:
<div><object data="ftp://username:pass#ftp.website.com/website.com/wwwroot/folderpath/test.pdf" type="application/pdf" width="800" height="1000"> alt : test.pdf </object> </div>
and it works well. Tho the ftp username and password are still shown in the page source. Any ideas? Thanks
es simplemente poner un: id="NombreCampo" y asignar igualmente un: runat="server" desde el código en el archivo .aspx, quedaría así:
< iframe id="NombreCampo" runat="server" width="400" height="500" style="border: none;">
eso sería lo visible al usuario en el código de la página.
desde el codigo de lado del servidor poner la cadena con el FTP:
NombreCampo.Src = "https://docs.google.com/viewer?url=ftp://nombreUsuario:pass#ftp.samplesite.com/" + NombreArchivo + " & embedded=true";
¡listo

Resources