private int StreamFile(string FilePath, string DownloadAs) { DownloadAs = DownloadAs.Replace(" ", "_"); System.IO.FileInfo objFile = new System.IO.FileInfo(FilePath); if (!objFile.Exists) { return(0); } System.Web.HttpResponse objResponse = System.Web.HttpContext.Current.Response; objResponse.ClearContent(); objResponse.ClearHeaders(); objResponse.AppendHeader("Content-Disposition", "attachment; filename=" + DownloadAs); objResponse.AppendHeader("Content-Length", objFile.Length.ToString()); string strContentType; strContentType = "application/octet-stream"; objResponse.ContentType = strContentType; WriteFile(objFile.FullName); objResponse.Flush(); objResponse.Close(); return(1); }
private static void UpdateChildPortalsDefaultPage() { DnnInstallLogger.InstallLogInfo(Localization.Localization.GetString("LogStart", Localization.Localization.GlobalResourceFile) + "UpdateChildPortalsDefaultPage"); //Update Child Portal subHost.aspx foreach (PortalAliasInfo aliasInfo in PortalAliasController.Instance.GetPortalAliases().Values) { //For the alias to be for a child it must be of the form ...../child int intChild = aliasInfo.HTTPAlias.IndexOf("/"); if (intChild != -1 && intChild != (aliasInfo.HTTPAlias.Length - 1)) { var childPath = Globals.ApplicationMapPath + "\\" + aliasInfo.HTTPAlias.Substring(intChild + 1); if (!string.IsNullOrEmpty(Globals.ApplicationPath)) { childPath = childPath.Replace("\\", "/"); childPath = childPath.Replace(Globals.ApplicationPath, ""); } childPath = childPath.Replace("/", "\\"); // check if File exists and make sure it's not the site's main default.aspx page string childDefaultPage = childPath + "\\" + Globals.glbDefaultPage; if (childPath != Globals.ApplicationMapPath && File.Exists(childDefaultPage)) { var objDefault = new System.IO.FileInfo(childDefaultPage); var objSubHost = new System.IO.FileInfo(Globals.HostMapPath + "subhost.aspx"); // check if upgrade is necessary if (objDefault.Length != objSubHost.Length) { //check file is readonly bool wasReadonly = false; FileAttributes attributes = File.GetAttributes(childDefaultPage); if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { wasReadonly = true; //remove readonly attribute File.SetAttributes(childDefaultPage, FileAttributes.Normal); } //Rename existing file File.Copy(childDefaultPage, childPath + "\\old_" + Globals.glbDefaultPage, true); //copy file File.Copy(Globals.HostMapPath + "subhost.aspx", childDefaultPage, true); //set back the readonly attribute if (wasReadonly) { File.SetAttributes(childDefaultPage, FileAttributes.ReadOnly); } } } } } }
public static void DownloadFile(string fileLoc) { var objFile = new System.IO.FileInfo(fileLoc); HttpResponse objResponse = HttpContext.Current.Response; string filename = objFile.Name; if (objFile.Exists) { objResponse.ClearContent(); objResponse.ClearHeaders(); objResponse.AppendHeader("content-disposition", "attachment; filename=\"" + filename + "\""); objResponse.AppendHeader("Content-Length", objFile.Length.ToString()); objResponse.ContentType = new FileManager().GetContentType(objFile.Extension.Replace(".", "")); #pragma warning disable 612,618 WriteFile(objFile.FullName); #pragma warning restore 612,618 objResponse.Flush(); objResponse.End(); } }