NET Link Tracker
CreateExpiringUrl Method
Example 



KellermanSoftware.NetLinkTracker Namespace > LinkLogic Class : CreateExpiringUrl Method
The url to track
How long before the link expires
Create a url that expires after the number of specified days
Syntax
'Declaration
 
Public Function CreateExpiringUrl( _
   ByVal url As String, _
   ByVal expirationDays As Integer _
) As TrackedLink
'Usage
 
Dim instance As LinkLogic
Dim url As String
Dim expirationDays As Integer
Dim value As TrackedLink
 
value = instance.CreateExpiringUrl(url, expirationDays)
public TrackedLink CreateExpiringUrl( 
   string url,
   int expirationDays
)
public:
TrackedLink^ CreateExpiringUrl( 
   String^ url,
   int expirationDays
) 

Parameters

url
The url to track
expirationDays
How long before the link expires

Return Value

The created tracked link
Example
LinkLogic linkLogic = new LinkLogic(); //Trial Mode
LinkLogic linkLogicLicensed = new LinkLogic("place user name here", "place license key here");  //License Mode
 
//Use a in memory mock database for testing
ILinkTrackerDatabaseLogic databaseLogic = new LinkTrackerMockDatabase();
 
linkLogic.DatabaseLogic = databaseLogic;
 
//Create a link to a URL that will expire in 30 days
TrackedLink createdLink = linkLogic.CreateExpiringUrl("http://www.google.com", 30);
 
TrackedLink link = linkLogic.GetLinkByGuid(createdLink.LinkGuid);
LinkStatus status = linkLogic.CheckLinkStatus(link);
 
//The status will be Active
Console.WriteLine("Status: " + status);
 
//Get a friendly status for the user
Console.WriteLine("Friendly Status: " + linkLogic.GetFriendlyStatus(link));
 
//Force the link to expire
link.ExpirationDate = DateTime.Now.AddDays(-1);
databaseLogic.SaveTrackedLink(link);
 
status = linkLogic.CheckLinkStatus(link);
 
//The status will be Expired
Console.WriteLine("Status: " + status);
 
//Get a expired friendly status for the user
Console.WriteLine("Friendly Status: " + linkLogic.GetFriendlyStatus(link));
 
//Get the associated URL
Console.WriteLine("URL:  " + createdLink.FilePathOrUrl);
 
//This will perform a Response.Redirect
if (HttpContext.Current != null) //This check not needed if running in ASP.NET process
    linkLogic.ProcessLink(createdLink);
Dim linkLogic As New LinkLogic() 'Trial Mode
Dim linkLogicLicensed As New LinkLogic("place user name here", "place license key here") 'License Mode
 
'Use a in memory mock database for testing
Dim databaseLogic As ILinkTrackerDatabaseLogic = New LinkTrackerMockDatabase()
 
linkLogic.DatabaseLogic = databaseLogic
 
'Create a link to a URL that will expire in 30 days
Dim createdLink As TrackedLink = linkLogic.CreateExpiringUrl("http://www.google.com", 30)
 
Dim link As TrackedLink = linkLogic.GetLinkByGuid(createdLink.LinkGuid)
Dim status As LinkStatus = linkLogic.CheckLinkStatus(link)
 
'The status will be Active
Console.WriteLine("Status: " & status)
 
'Get a friendly status for the user
Console.WriteLine("Friendly Status: " & linkLogic.GetFriendlyStatus(link))
 
'Force the link to expire
link.ExpirationDate = Date.Now.AddDays(-1)
databaseLogic.SaveTrackedLink(link)
 
status = linkLogic.CheckLinkStatus(link)
 
'The status will be Expired
Console.WriteLine("Status: " & status)
 
'Get a expired friendly status for the user
Console.WriteLine("Friendly Status: " & linkLogic.GetFriendlyStatus(link))
 
'Get the associated URL
Console.WriteLine("URL:  " & createdLink.FilePathOrUrl)
 
'This will perform a Response.Redirect
If HttpContext.Current IsNot Nothing Then 'This check not needed if running in ASP.NET process
    linkLogic.ProcessLink(createdLink)
End If
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

LinkLogic Class
LinkLogic Members