I have a static, informational PDF files that is going to be a part of the module, and the users are clicking the same link, and based on their role the correct PDF file is downloaded.
Here's my solution (might help somebody):
protected void cmdReviewInfo_Click(object sender, EventArgs e)
{
try
{
string strPath = Server.MapPath("~") + @"DesktopModules\ModuleName\FilesFolder\";
string strContentType = "application/pdf";
string strFileName = "";
if (PortalSecurity.IsInRole("CustomRoleOne"))
{
//get the required info
strFileName = "RequiredInformation_One.pdf";
DownloadFile(strPath, strFileName, strContentType);
}
else if (PortalSecurity.IsInRole("CustomRoleTwo"))
{
//get the required info
strFileName = "RequiredInformation_Two.pdf";
DownloadFile(strPath, strFileName, strContentType);
}
else
{
Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(), true);
}
}
catch (System.Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
///
/// Downloads a file
///
///
Path to the directory
///
File Name of a document/file
///
Content Type of the downloadable file (e.g. application/pdf)
public void DownloadFile(string strPath, string strFileName, string strContentType)
{
if (File.Exists(strPath + strFileName))
{
Response.ContentType = strContentType;
Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
FileStream sourceFile = new FileStream(strPath + strFileName, FileMode.Open);
long FileSize;
FileSize = sourceFile.Length;
byte[] getContent = new byte[(int)FileSize];
sourceFile.Read(getContent, 0, (int)sourceFile.Length);
sourceFile.Close();
Response.BinaryWrite(getContent);
}
else
{
MsgBox("The file is missing!");
}
}
These forums are not code friendly at all, which should be opposite...
Cheers,
Val