|
Hi,
I want to open only one PDF file using singleton pattern.I have written a code as follows on button click event:-
FileInfo objFile;
string strFileName;
strFileName = "User Manual - Quality Feedback System.pdf";
objFile = new FileInfo(Server.MapPath(ConfigurationSettings.AppSettings["App_Name"]) + "\\" + strFileName);
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + objFile.Name);
Response.Flush();
Response.WriteFile(objFile.FullName);
Response.End();
The problem with the above code is that it opens more than one PDF file if button is clicked more than once.How can I make sure that one PDF file gets opened using Singleton design pattern.I am clear with the concept of singleton pattern but I am not able to implement this concept in my problem.Please help.
|
|
|
|
|
are you loading the pdf file where the button exists?
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
Pranav Thakur wrote: The problem with the above code is that it opens more than one PDF file if button is clicked more than once.How can I make sure that one PDF file gets opened
Disable the button so that it can't be clicked again?
Pranav Thakur wrote: I am clear with the concept of singleton pattern
That seems unlikely given your post.
led mike
|
|
|
|
|
If you would apply the singleton pattern to this, it would mean that only one user could open the PDF file. Then you would have to restart the web application before another user could look at it...
I assume that what you really want to do, is to limit the usage per user, not per application. The problem is that the method that you use to open the file effectively prevents any attempt to check if the file is already open or not. The server code has no means at all of checking this, and you would have to open a window using client side code to have a chance to determine if there is already a window open or not. Even then, it depends on how the file is opened by the browser. If it's not opened in a browser window, but in a separate application (i.e. Adobe Reader), you can't determine if the file is still open or not. I'm not certain that it's ossible even if it's opened in a browser window.
So, what you want to do falls somewhere between "maybe working sometimes" and "impossible". Either way it's definitely not possible to implement the way that you suggest.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Ok, my purpose was to understand singleton pattern with some live example.Can anyone please explain this singleton pattern with suitable example.
|
|
|
|
|
Singleton Pattern is used when only one instance of a class is needed to provide services. In other words, only one instantiation. Here is an example:
public class SingletonClass
{
private static SingletonClass _myInstance;
//Private constructor so clients can not instantiate
private SingletonClass
{
}
// Clients call this when they need an instance of this class
// Needs to be static as it can be called without instantiation or instance of this class
public static SinletonClass getInstance()
{
if (_myInstance == null)
{
_myInstance = new SingletonClass();
}
return _myInstance;
}
}
The whole idea is the class checks whether an instance is available, if yes it returns it, else creates and returns it.
Let me know if you have questions.
|
|
|
|
|
Hi all,
I am trying to set the text property to the asp:hyperlink control using
frmHourRegistration.hlProject.Text="Test"
But I am gettting the error as "Method not supported"
What I am doing wrong here ?
|
|
|
|
|
try
hlProject.Text="Test"; in your codebehind if hlProject is the id of the hyperlink
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
Thanks for the reply Sylvester george ,
It works well in the code behind. But i want to populate from VBScript function. How can I ?
|
|
|
|
|
Anyway that you have not mentioned in the question.
this is the code for you
<script type="text/vbscript"><br />
HyperLink1.innerText = "abc"<br />
</script>
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
This is my code
Sub btnProjects_Click<br />
Dim retValue<br />
If frmHourRegistration.chkShowAll.checked=true then<br />
retValue= window.showModalDialog("test.aspx",window, "dialogWidth:550px;resizable:yes")<br />
If IsNull(retValue) Then<br />
frmHourRegistration.txtProject.Value=Empty<br />
frmHourRegistration.hlProject.Value=Empty <br />
Else<br />
frmHourRegistration.txtProject.Value=retValue(0)<br />
frmHourRegistration.hlProject.Text=retValue(1)<br />
End If<br />
End If <br />
End Sub
|
|
|
|
|
Hi friends
I am able to send mail to the id of same domain but not to other....
this is the code and below of the code is error
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.From = new MailAddress(frmEmail);
message.To.Add(new MailAddress(txtEmailAddress.Text));
message.Subject = " From "+ Label1.Text + " Your Booking Information " ;
message.Body = booking_body;
SmtpClient client = new SmtpClient();
client.Host = hostname;
client.UseDefaultCredentials = false;
System.Net.NetworkCredential auth = new System.Net.NetworkCredential(user_name,password);
client.Credentials = auth;
client.Send(message);
ERROR:
Syntax error, command unrecognized. The server response was: mr.sindhutiwari@yahoo.com relaying prohibited. You should authenticate first
please tell me where i am going wrong
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
you can set the relay property of SMTP server by following steps
open IIS
Right click on default SMTP server, then select properties
gott Access tab, there you will find Relay button, there you set the Relay restrictions.
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
Can you send e-mail to local address but not web address like yahoo and hotmail?
|
|
|
|
|
my mail server is mail.abcd.com so i am able to send mails to any id of this domain like xyz@abcd.com but when i tried to send it to other ids error raised
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
Hi
I have just tried implementing a new control for RSS feeds for my website
The control worked fine locally but when I put it on the server it returned the above error message.
Anyone knows why this would be?
cheers
|
|
|
|
|
that means server unreachable from your server. Try to open the port to access particular host
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
So what your saying is that there is a port on the server which is blocking rss feeds from other websites
|
|
|
|
|
that could be one reason
Regards,
Sylvester G
If we don't succeed, we run the risk of failure
|
|
|
|
|
hi,
i hav a problem. i require a functionality in my website that when i'm logged out of my website and if i've pressed back button after logging out, i am coming to the same page. where as i want session to be deleted for that user and it shouldn't navigate back instead it should say that user has been logged out. please help, its urgent.[
thanks in advance...
Shraddha
|
|
|
|
|
try
System.Web.Security.FormsAuthentication.SignOut().
|
|
|
|
|
The autoeventwireup , if it is set to false , it will not execute the code written in the page load function , and reverse is true.
My question is , how should i implement this case in the project and in which situation i should use it?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
if ajax is incorporated with my project , i can easily invoke the message box using scriptmanager.registerstartupscript(......), what should i do in case , i am not using the ajax in the project?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|
|
Can you explain that again please
If you are not using ajax in your project you dont need scriptmanager
|
|
|
|
|
The issue is , i am not being able to invoke the message box.Now , for some reasons i used ajax in the project.Subsequently , i got the scriptmanager class.Through this class , i can invoke the message box , using the below code.
scriptmanager.registerstartupscript(page,typeof(page),"","alert('message box');",true);
if i am not using the ajax in the project.Then the script manager class does not includes in the intellisence.
Now , how should i invoke the message box?
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
|
|
|
|