|
OK Abhijit,
Sorry about the delayed response. I had to leave for a bit.
Thank you for the insight, but as I said in the post, it is not a hard coded link. There are over 1500 pdf's that can be called, depending on the results of the search. How do I pass the variable for the correct one in the form of a link so it can be accessed and clicked on by the Client? If you can, please supply a code sample that I can work from that will coordinate with the actual code that I supplied in the original request.
Thank You
Regards, Pat
|
|
|
|
|
From your first post.
PDTUM wrote: //Get the information from the cell
this.thePdf = gvr.Cells[theCell].Text;
Does it contain the actual pdf file path ?
You need to bind the pdf path at runtime only.
|
|
|
|
|
Hello Abhijit,
The path is not part of the returned string. The permanenet path to all the pdf's will always be
(App_Data/Pdfs/pdf001.pdf) WHERE pdf001.pdf is the name of the selected pdf. The returned string value will always look like (pdf001.pdf).
So....I need to know how to pass this to a link in code. In C#, I do it like this:
System.Diagnostics.Process.Start(Application.StartupPath + @"\PDFs\" + pdf);
Obviously, this will not work in ASP.net. All that should be necessary is to be able to create a link when the grid link is clicked on that uses the value of the pdf string variable as returned from the GridView so that when the line is selected from the GridView, it automatically creates the link and deploys it so that the client's PDF reader will launch and load the pdf. However, I do not know how to accomplish this.
If there another or better way, do let me know and supply me an example using the code sample that I submitted as a starting point....Thank You
Best Regards, Pat
|
|
|
|
|
Don't Store PDF in APP_DATA . Creates another folder like Files\Pdf under root directory and store the PDF over there.
Because
App_Data Folder used as a "data storage " for the web application. It can store, .mdf, .mdb, XML, etc files. It can be accessible from any where of your web application. The real advantage is that any file you place in App_Data won't be downloadable.
Hope you got my point.
Here is one of my complete Article on ASP.NET Application Folder. You may look into it.
ASP.NET Application Folder
|
|
|
|
|
Thank You Abhijit,
Actually, that is exactly what I did. I am sorry I was not clear about it, but I did not define it in detail since that is not the problem I was asking about. The path to the files is /App_Data/PDFs/file001.pdf. Thank you for the tip. Now, if I could get an answer to the original problem of how to create a hyperlink that will accept a variable depending on the line that was selected, I could finish this application. Any help you could give there would be appreciated. Best Regards, Pat
|
|
|
|
|
I have one quick suggestion to implement it, You can store only the file path in the Table (Store File in Physical Location) . And bind with the Grid view Hyperlink Field.
Here is an good Example, Hope this will help you
how to download files from a gridview?
|
|
|
|
|
Abhijit,
Thank you for your help.....and all others that responded to my request. Your help is greatly appreciated. I have come up with a solution for this dilemma, as submitted to me by PeteNet at the ASP.Net forum. It is nice and tight, easy to understand, and works perfectly. I wish to post it here for the benefit of all others that might be interested.
use a LinkButton within a TemplateField in your GridView:
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandArgument = '<%#Eval("<filename>")%>' OnClick="OpenPDF">OpenPDF</asp:LinkButton>
</ItemTemplate>
in the codebehind write the event handler OpenPDF:
protected void OpenPDF(object sender, EventArgs e)
{
LinkButton lnk = (LinkButton)sender;
if (lnk != null)
{
Response.AddHeader("content-disposition", "attachment; filename=" + lnk.CommandArgument + ".pdf");
Response.WriteFile(Server.MapPath("~/PDFs/" + lnk.CommandArgument.ToString() + ".pdf" ));
Response.End();
}
}
commandArgument will hold the filename (from the database, for the current row in the grid)...depending on whether you have the extension stored along with the filename you may want to append or remove ".pdf" in the code (lnk.CommandArgument + ".pdf")
replace <filename> with the actual value of your database column name that holds the file name
if you use VB.NET you can convert over here: http://www.developerfusion.com/tools/convert/csharp-to-vb/
Good Luck and Best Regards to All, Pat
|
|
|
|
|
|
Error It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level.
This error can be caused by a virtual directory not being configured as an application in IIS.
C:\Inetpub\wwwroot\sample10\XmlDataSource\web.config 46
ramesh reddy
ramesh.sanikommu@gmail.com
|
|
|
|
|
Do you have multiple web.config in the application?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Ramesh Reddy11111 wrote: This error can be caused by a virtual directory not being configured as an application in IIS.
This is indeed a beautiful example of error handling where it is clearly saying that what the problem is.
You have a directory in your application which contains another web.config. You should convert this directory into application. Use the Convert to Application option from the IIS menu.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
yes my project consists of many folders and each folder consists of one web.config file. how to convert application level ?
|
|
|
|
|
Ramesh Reddy11111 wrote: . how to convert application level ?
If you are using IIS 7, then you need to convert it to Application other wise you have to create the Virual Diectory.
Goto > IIS > Right Click on Your web site > Properties > Default TAB > There should be a create button, Click it.
Make sure, ASP.NET Version us set properly, check it from ASP.NET Version Tab.
|
|
|
|
|
i am using windows XP SP2 default IIS.
Asp.net version is 2.0.50727. I followed your procedure but same problem. in my project consists of seven folders and each folder consists of one web.config file and web.config file consists of authentication mode="Windows" tag. is it any problem.
|
|
|
|
|
Ramesh Reddy11111 wrote: in my project consists of seven folders and each folder consists of one web.config file
Dont you think it is a wierd design.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Ramesh Reddy11111 wrote: I followed your procedure but same problem.
Did you Click On "Create Button" on Default Tab (Virtual Directory) in IIS ? I don't think so.
Here is another link, which may help you to learn the details of using multiple web.config.
Working with more than one Web.config file
|
|
|
|
|
Hello,
There are four buttons on the asp.net form.
Each has a different ID i.e. Back, Pause, Play, Forward
The commandName property of each button is set to Playback.
I have the event below which is supposed to be fired every time I click on one of these buttons. Do you see why this event does not get fired please?
have I done something wrong?
Thanks
protected void Playback_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "Back":
Response.Write("back");
break;
case "Pause":
Response.Write("pause");
break;
case "Play":
Response.Write("play");
break;
case "Forward":
Response.Write("Forward");
break;
}
}
|
|
|
|
|
arkiboys wrote: s. Do you see why this event does not get fired please?
have I done something wrong?
Did you tried to check using debugging the value of e.CommandName . Did u sent the value of CommandName of button?
one sample ,
<asp:Button ID="Button1"
Runat="server"
Text="Button 1"
OnCommand="Button_Command"
CommandName="DoSomething1" />
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I have now made this code simpler and have two buttons now as follows:
<asp:Button ID="Back" runat="server" CommandName="Playback" Text="Button" />
<asp:Button ID="pause" runat="server" CommandName="Playback" Text="Button" />
None of these buttons call the playback_command event.
|
|
|
|
|
The Command event is usually used within the context of a databound control, like a repeater, gridview, or datagrid to simplify how button presses in each databound item are handled by the developer.
For example, you have multiple buttons in the ItemTemplate for a repeater, you set their CommandName and CommandArgument propertiers accordingly (with CommandArgument usually databound to a field in the source). Then you trap the Command event for the repeater. The CommandName and CommandArgument values are passed through the arguments of the event handler.
From what you posted, it looks like you just have standalone buttons - buttons that are not part of an item template in a databound control. Is that right? If so, why not just use the Click event?
|
|
|
|
|
Hi, Yes I just have stand alone buttoons.
I just want to learn the way to reduce the number of events by simplyfying them into just one event
Thanks
|
|
|
|
|
You can set some variable, Suppose, Action. If Action=0 then Play, Action=1, Pause etc. And On button click check the Action value and do the operation.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I do know that there is a way to setup an event for all the buttons. Do not remember it.
|
|
|
|
|
|
This link made it clear.
Many thanks
|
|
|
|