|
Hello everyone,
I've been struggling with this for the last 6 hours, and after a lot of google-ing and research, I thought I'd ask for a little help. See:
a) I have a PDF document exported to a MemoryStream.
b) The control firing the event which leads to the PDF generation and exporting is inside an AJAX UpdatePanel .
So all I want to do is to send the contents of that MemoryStream (containing the PDF) to the browser, so the user sees an "open or download" dialog. As far as I remember, it used to be really easy, at least before AJAX times. Now I've learnt over researching, that the AJAX framework doesn't like Response.Write() at all, but despite my searching, I haven't found a workaround yet.
Here's the way I do it:
Public Sub ExportarPDF(ByVal rpt As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal Nombre As String)
Try
Dim ms As IO.MemoryStream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment; filename=" & Nombre & ".PDF")
Response.BinaryWrite(ms.ToArray())
Response.End()
Catch ex As Exception
Throw ex
End Try
End Sub
And the error it returns (as far as I know, whenever you use Reponse.Write() on an AJAX postback):
Sys.WebForms.PageRequestManagerParserErrorException" The message received from the server could not be parsed. [...] Error parsing near '%PDF-1.2
%????
10'
Where the ? is actually some sort of ? with a question mark inside that I cannot find in the ascii catalog.
Please, if anyone has any ideas of how can I make a browser display the open or download dialog from an AJAX postback, let me know.
Thanks in advance!
Kazz
"Users are there to click on things, not think. Let the archs do the damn thinking."
|
|
|
|
|
You can't send a response like that via AJAX, the browser is simply not expecting it. Nor do you need to, if you have a link and it does a binary write, your page will not refresh, so the end effect is the same as if you used AJAX.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Code:
using System;
using System.IO;
using System.Configuration;
using System.Data;
using System.Collections;
using System.Text;
partial class Default2 : System.Web.UI.Page
{
private string[] strDictArray;
private bool boolDictionaryLoaded = false;
private int intErrors = 0;
protected void Page_Load(object sender, System.EventArgs e)
{
int iCurrentCount = 0;
string[] arrWords;
string strCompleteOriginal = "";
int iWordCount = 0;
string strAlternative = "";
int i = 0;
if (string.Trim(Request.Querystring["txtContent"]) == "")
{
return; // TODO: might not be correct. Was : Exit Sub
}
else
{
strCompleteOriginal = string.Trim(Request.Querystring("txtContent"));
}
if (!IsPostBack==false)
{
iCurrentCount = 0;
iWordCount = 0;
intErrors = 0;
hfOriginalstring.Value = strCompleteOriginal;
hfCurrentCount.Value = "0";
arrWords = string.Split(strCompleteOriginal, " ");
iWordCount = arrWords.Length;
hfWordCount.Value = iWordCount;
hfErrors.Value = "0";
}
else
{
arrWords = string.Split(hfOriginalstring.Value, " ");
iCurrentCount = hfCurrentCount.Value;
intErrors = int.Parse(hfErrors.Value);
}
txtCurrent.Value = arrWords[iCurrentCount];
if (Request.Form["cmdCancel"] == "Stop")
{
arrWords = string.Split(hfOriginalstring.Value, " ");
iWordCount = hfWordCount.Value;
string strReplace = hfFinal.Value;
int j = 0;
for (j = iCurrentCount; j <= iWordCount - 1; j++)
{
strReplace += arrWords[j] + " ";
}
intErrors -= 1;
stopChecking("frmSpellCheck", "txtContent", strReplace);
return; // TODO: might not be correct. Was : Exit Sub
}
if (Request.Form["cmdNext"] == "Next")
{
arrWords = string.Split(hfOriginalstring.Value, " ");
iWordCount = hfWordCount.Value;
if (txtManual.Value == "")
{
arrWords[iCurrentCount] = lbSuggestions.SelectedValue;
hfFinal.Value += lbSuggestions.SelectedValue + " ";
}
else
{
arrWords[iCurrentCount] = hfFinal.Value;
}
}
}
protected void lbSuggestions_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Error:
1.System.Web.HttpRequest does not contain a definition for Querystring
2.The best overloaded method match for string.Split(params char[])
3.cannot convert from string to char
4.System.Web.UI.WebControls.TextBox does not contain a definition for value
Please find me a solution
|
|
|
|
|
Well, those errors are all true. Do you know C# at all ? I am assuming you copied some code from the web and have no idea how to understand these error messages. If I were to correct them for you, you'd still be lost. Buy a basic book on C# and read it. Read the error messages, what they say is true.
1 - C# is case sensitive. QueryString
2 - Did you mean to call Split or Replace ? Split expects a char, not a string.
3 - a string is an array of chars
4 - TextBox most certainly does not contain a definition for Value. It DOES have a Text property.
Please try to learn some basics, and perhaps even learn to do some searching, we love to help, but we'd like to assume some basic effort/ability on the part of those asking, too.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Hello,
i have made a very simple file upload app, that i want users to be able to upload images to a folder on my server, well localhost for the time being
here is the simple upload code...
protected void ButtonRegisterDetails_Click(object sender, EventArgs e)
{
String FileName = MyFile.PostedFile.FileName;
String FileContent = MyFile.PostedFile.ContentType;
int FileSize = MyFile.PostedFile.ContentLength;
String justFileName = Path.GetFileName(FileName);
try
{
MyFile.PostedFile.SaveAs(@"C:\Downloads");
ProgressTextBox.Text = "uploaded ok.... i think";
}
catch (Exception ex)
{
ProgressTextBox.Text = ex.Message.ToString();
}
}
The code looks fine but the problem i have is that i keep getting an exception saying that the access to the destination folder is denied.
Access to the path 'C:\Downloads' is denied.
Ive been reading about granting permissions for 2 days now, and although im new to IIS i believe that because i have the NETWORK SERVICE but not ASPNET user available im using IIS 6.
in a disparate attempt to try and solve this i created a new project using the same C# code as above and pointed the images to be saved in a new directory "C:\Downloads". i granted full access permissions to all the users that were listed when i right clicked on the C:\Downloads dir and selected....
Sharing and Security
Security tab
add
Advanced
Find Now
The users that people have said should work "IUSR_mycomputer" and "NETWORK SERVICE" make no difference either, but even by giving all users, well over 60 of them full access permissions it makes no difference.
could it be something to do with the way ASP.NET, or IIS is installed on my machine ??
Im using Windows XP pro 64bit and Visual studio 2008.
basically my question is.... how can i grant write permissions to a folder in my asp.net app as changing permissions in the Sharing and Security properties has done nothing ??
thank you for your time.... please help
Truegilly
|
|
|
|
|
ok ive got it working,
it was my code, i needed to add the file name of the uploaded file
MyFile.PostedFile.SaveAs("C:\\Downloads\\" + justFileName);
also i lost the @ at the beginning
thanks
Truegilly
|
|
|
|
|
Hi,
I am using asp.net 2005.
I have a problem with usercontrol.
I have a usercontrol on my aspx page.
In usercontrol there is a button.
on click event of usercontol button i have to fill gridview which is present on aspx page.
can any one tell me how i will do it.
thanking u.
|
|
|
|
|
well fire the event for filling the gridview on the onclick event of the button
there are plenty of tutorials for binding data to a gridview and its fairly straightforward
We are not a Code Charity
|
|
|
|
|
thanks for replaying me.
but the problem is
my button is in usercontrol and gridview is in aspx page.
how i fire event of usercontrol in aspx page.
please tell me.
|
|
|
|
|
check this out:
http://forums.asp.net/p/1279478/2441374.aspx
and this
http://forums.asp.net/p/1262933/2365263.aspx
We are not a Code Charity
|
|
|
|
|
Hi,
Sorry for the delay...there was a problem in the site..
You need to raise an event to the page. Here is how to do it.
First let’s create delegate and define an event of type of the delegate. And call that event in the button click event.
Add this code your ascx.cs file
public delegate void LoadGridHandler();
public event LoadGridHandler LoadGrid;
protected void Button1_Click(object sender, EventArgs e)
{
this.LoadGrid();
}
Now, in your aspx file, raise that event during the page load of your page.
Take this code..
protected void Page_Load(object sender, EventArgs e)
{
MyControl1.LoadGrid += new Controls_MyControl.LoadGridHandler(MyControl1_LoadGrid);
}
void MyControl1_LoadGrid()
{
//write the method to load you grid
Response.Write("Hi from Gayani");
}
Hope it works
Thx,
Gayani
|
|
|
|
|
thanks a lot.
i fixed my problem.
|
|
|
|
|
Hello!
I've got an aspx-file which I use for AJAX to return different stuff depending on querystring. I one case I return an webusercontrol(.ascx) with a bunch of controls including a couple of validators. When I try to do this:
myWebUserControl.RenderControl(myHtmlTextWriter)
none of the asp:validator-controls gets rendered in html. This includes asp:RequiredFieldValidator and asp:ValidationSummary. What do I have to do in order for those controls to also be rendered?
|
|
|
|
|
In design mode drag the .ascx onto the form. put the control inside a panel
in the page load set panel.style.value = "display:none";
in ajax event when you want to display the ascx set panel.style.value = "";
Did that help?
I didn't get any requirements for the signature
|
|
|
|
|
Hello and thanks for your reply! Actually this did solve part of the problem. Now I do get html for the validators like this:
span id="Login1_validatorReqFieldUserName" style="color: Red; display: none;"
but I don´t seem to get the javascripts that makes the actual validation work.
|
|
|
|
|
ButtonClick
strSql = "Select [Type],[Image] from [Details]"
cClass.ExecuteReader(strSql)
If cClass.dataReader.Read Then
TextBox1.Text = cClass.dataReader.Item("Type").ToString
Image1.ImageUrl = cClass.dataReader.Item("Image")
End If
End ButtonClick
'Class here
Public Sub ExecuteReader(ByVal strSql As String)
Try
codeSuccess = False
dataCommand = New SqlCommand(strSql, oConn)
dataReader = dataCommand.ExecuteReader()
codeSuccess = True
Catch ex As Exception
errMsg = ex.Message.ToString
End Try
End Sub
'End Function
I want to show a pic in an Image1 but it does not work, any suggestions please.
Thanks in advance
Phetolel
|
|
|
|
|
phetolel wrote: but it does not work
what is happening?
Have you def got an image stored in the datbase, is it stored in the correct format?
We are not a Code Charity
|
|
|
|
|
I've got an image stored in ms sql 2005
the field is of image type.
thanks
|
|
|
|
|
what is happening?
Are you getting an error?
We are not a Code Charity
|
|
|
|
|
I'm getting this error
Conversion from type 'Byte()' to type 'String' is not valid.
|
|
|
|
|
check this out:
http://www.aspfree.com/c/a/ASP.NET/Retrieving-Images-from-a-Database--C---Part-II/
your error is a big clue, which line of the code does it have a problem with, is it this line:
TextBox1.Text = cClass.dataReader.Item("Type").ToString
We are not a Code Charity
|
|
|
|
|
i made a class to export gridview to excel.....its working fine on local server...but when i upload this class on server it is giving this error...
The name 'GridViewExportUtil' does not exist in the current context
please tell me how to use this class..
|
|
|
|
|
I might be wrong but is the class stored in the correct folder, i.e. app_code folder?
We are not a Code Charity
|
|
|
|
|
yeah i put my class in App_Code folder....should i make dll for my class...i didn't make that....please help me
|
|
|
|
|
It depends how your website functions.
Have you previously copied a dll across?
I know that if you write the c# in visual studio and then upload dll then the most updated pages of code must be in that dll
To answer your question then yes put it in the dll
We are not a Code Charity
|
|
|
|