|
Hi,
I am working on a website and on the home page we have a pdf file link. The moment user clicks on that link the control takes the user to new URL, also displays the URL in the Address line of Browser, where the PDF file exists. However I don't want to show this URL to user, so that he can't copy and paste that URL in another browser.
Is there any way possible to hide such details or is it possible to just download the pdf without showing the URL (one where PDF file actually exists) in the address line of the browser. If user is able to download also it is fine. The only thing we need is to hide the URL.
Thanks in Advance!!
|
|
|
|
|
you can zip that pdf then user download it wirhout opening in another browser
|
|
|
|
|
You can use the Content-Disposition HTTP header to force the file to download and not open in the browser. No zipping required.
|
|
|
|
|
If you are using ASP.NET you can create an aspx site where you check if the user
has the right to download/see the pdf (maybe through a temp guid). If he has the right, then you can
send this pdf through the response stream to the client pc.
Example:
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GetPDF.aspx.cs" Inherits="[namespace].GetPDF" %>
.cs
public partial class GetPDF : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.BufferOutput = true;
Response.Cache.SetNoServerCaching();
Response.Cache.SetNoStore();
Response.OutputStream.Write(buffer, 0, buffer.Length);
}
catch (Exception)
{
}
}
}
Maybe the user sees the url "http://.../GetPDF.aspx?querystring" but through your check, copy and paste the url
will not work. (You could create a temp guid to access the pdf for the user, provide it in the querystring and delete
this temp guid after downloading. On the next call of this url the user will not be able to download it again.)
Hope this helps.
Edit:
In addition to the example above, you can also use the session object to check if the user has the rights to access the pdf file. Just set a session value (like Session["UserCanAccessPDF"] = true; ) on link click event and check this session value on GetPDF::Page_Load. If the session value is invalid or not set, just redirect to an error page (or something else). If the value is valid, send the pdf trough the stream and delete the session value.
Greetings
Covean
modified on Thursday, April 29, 2010 7:01 AM
|
|
|
|
|
Assuming ASP.Net...
Create a button. In the click handler, write the file to the HTTP response, as the previous poster suggested. That way, you aren't using a different URL. The only way they can get the file would be to click the button. You can have whatever logic you like to decide when to display that button, or if they manage to click the button when they are not allowed, you can add additional validation to prevent the download. You could, for example, validate that the user has never downloaded the PDF before so that they can't download it a second time. If they have already downloaded it, you could show a message that says "sorry, but you are only allowed to download this PDF once". The PDF data you return can come from the server file system or from a database on the server (or even from another server). Where you want to get the PDF from is up to you.
|
|
|
|
|
|
Not sure that's what the OP is after, but perhaps you should redirect your answer to the OP anyway. It's certainly going to do me no good.
|
|
|
|
|
ups... sorry aspdotnetdev! ok! my answer was:...............
Perhaps you can use Server.Transfer("url");[^] instead of Response.Redirect("url");.....
good luck
|
|
|
|
|
Hi.
I have an array of images like:
Image[] images = new Image[3];
After populating it with three images, i want to remove all of them and prepare it for the next set of three images by clearing the array. i have tried:
images.Clear();
as in an array but this does not work. How do i remove the images?
Thank you in advance.
Wamuti: Any man can be an island, but islands to need water around them!
Edmund Burke: No one could make a greater mistake than he who did nothing because he could do only a little.
|
|
|
|
|
Have you tried repeating step 1
images = new Image[3];
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Wamuti wrote: How do i remove the images?
What do you mean by "remove"? you can't remove anything from an array, each element will be there, all you can do is replace it, possibly by null.
If you want a variable number of elements, use a real collection such as a List<Image>
If you are worried about memory clean-up (and you should), then call Dispose() on each non-null element before replacing it by something else (unless the same image is still needed elsewhere).
|
|
|
|
|
If you want the elements to vary and you want to keep using an array and you don't want to reference a new array, you could always try:
Image[] images = new Image[3];
Array.Resize<Image>(ref images, 0);
Array.Resize<Image>(ref images, 4);
|
|
|
|
|
Two days in row, two different questions (yesterday's problem is solved by the way )
This is another one where I need some creative ideas...
I need to find all groups of items in an array. In this case same items in a different order means same group. The array/set/... is prepared by some methods that are executed earlier. This means I could start with 1 item, but with 250 items as well.
Let's suppose the generated array/set/... contains 5 items A, B, C, D and E. The groups I should get as result are the following:
A - B - C - D - E
AB - AC - AD - AE - BC - BD - BE - CD - CE - DE
ABC - ABD - ABE - ACD - ACE - ADE - BCD - BCE - BDE - CDE
ABCD - ABCE - ABDE - ACDE - BCDE
ABCDE
I don't need to reuse the combinations afterward. I just need the algorithm to perform a check routine on each group (and it occurs on only one place in my program). A little like "loop { check(group) }"
Thanks in advance for your ideas!
modified on Friday, April 30, 2010 4:21 AM
|
|
|
|
|
That looks like the power set minus the empty set
How about (in pseudocode - untested):
void TestAll(int i)
{
if (i == numberOfItems)
{
check(test-set)
return
}
TestAll(i + 1)
add input[i] to the test-set
TestAll(i + 1)
remove input[i] from the test-set
}
It includes the empty set but oh well..
Just an idea - I can't test it now though because I have to go, I'll be back in 8 hours or so
|
|
|
|
|
At first glance it looks good but I don't really understand what you mean. Could you (or somebody else) post a code snippet? Thanks in advance!
|
|
|
|
|
Here's another way of looking at it:
You have a binary number with as many bits as you have items. E.g. for ABCDE you'd have a 5-bit binary number. You then go through all the possible binary numbers of this length (i.e. the power set):
00001
00010
00011
00100 etc...
(In this case you'd ignore 00000 (no items)).
Where there's a 1 bit, you select the item. So the first four groups would be:
E (from 00001)
D (from 00010)
DE (from 00011)
C (from 00100)
This will go through every possible group of selections from the items, without regard to order.
|
|
|
|
|
With my Combinations extension method, I can do:
char[] b = new char[] { 'A' , 'B' , 'C' , 'D' , 'E' } ;
for ( int i = 1 ; i <= b.Length ; i++ )
{
foreach ( System.Collections.Generic.IList<char> a in b.Combinations ( i ) )
{
foreach ( char c in a )
{
System.Console.Write ( "{0} " , c ) ;
}
System.Console.WriteLine() ;
}
}
|
|
|
|
|
I've continued looking while I was waiting for answers and I found a quite simple way to do this. For my program, I had to build in a treshold calculation for performance purposes, but that's already done. Just the loops:
class ComboSearcher {
private string[] _arCombos;
private int[] _arIndeces;
private string[] _arSourceArray;
public ComboSearcher(string[] SourceArray) {
_arSourceArray = SourceArray
}
private void AddItemInt(ref int[] ArrayToUpdate, int ItemToAdd) {
int[] tmpArray;
tmpArray = new string[ArrayToUpdate.length];
for(int i=0; i<ArrayToUpdate.length; i++) {
tmpArray[i] = ArrayToUpdate[i];
}
ArrayTuUpdate = tmpArray;
}
private void CutArrayInt(ref int[] ArrayToCut, int NewLength) {
int[] tmpArray;
tmpArray = new int[NewLength];
for(int i=0; i<NewLengh; i++) {
tmpArray[i] = ArrayToCut[i];
}
ArrayToCut = tmpArray;
}
private void SubCheck(int IndexNumber) {
int i, j, minCount;
_arCombos = new string[0]
AddItemInt(_arIndeces, 0);
if(_arIndeces.lengh > 1) {
minCount = _arIndeces[_arIndeces.length - 2);
}
else {
minCount = 0;
}
for(i=minCount; i<_arSource.length; i++) {
_arIndeces[IndexNumber] = i;
for(j=0; j<=IndexNumber; j++) {
}
if(_arIndeces.length<_arSourceArray.length) {
CutArrayInt(_arIndeces, IndexNumber + 1);
}
}
}
public string[] Combinations() {
_arCombos = null;
SubCheck(0);
return _arCombos
}
}
Usage:
ComboSearcher cboSearch;
cboSearch=new ComboSearcher(source);
target=ComboSearcher.Combinations();
|
|
|
|
|
If you have 64 items or less (you better hope so, otherwise it will take forever) you could just use the bits in an ulong - that might complicate your check method a bit depending on your datastructures though
|
|
|
|
|
If you can find a copy, Volume 4 Fasicle 3 of Donald Knuth's The Art Of Computer Programming is pretty much the definitive work on combination generator algorithms.
Wikipedia's article[^] on the topic has a reference to Gosper's hack down at the bottom which may be of some use to you. It's a nifty hack to get the next highest number with the same number of 1 bits in the binary representation. Each bit of the output should correspond to an entry in your generated array. Run this for each bit count from 1 to the number of items in your array and you should have your combinations.
Of course, if you have more than a few items in your array, you should probably find some other way to check whatever it is you're checking. Generating combinations is order O(N choose t), so the running time is going to get big pretty quickly the more items you have in your array.
|
|
|
|
|
Hi everyone,
I'm writing a C# forms application to open an existing Excel workbook using the Excel Interop. Everything works fine. I can read and write fine. I do not save the workbook until the user close the C# application. The problem happens when my program is running and the user accidentally opens the same workbook with Excel. I get the error:
Exception from HRESULT: 0x800401A8
at this line
Range excelRange = worksheet.UsedRange;
Is there a way to lock the workbook and not allow the user to open it with Excel when my program is running?
Thanks
|
|
|
|
|
please any one can tell me when we need to generate event using delegates and please send me code of event handling using delegates.
thanks in advance
|
|
|
|
|
See here..., It may Help You..,
Delegates & Events [^]
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
|
A lots of resource on the internet. Why don't you try to search at google first.
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|