void btnExport_Click(object sender, EventArgs e) { if (CurrentForm != null) { string fileName = string.Concat("_", CurrentForm.Name, DateTime.UtcNow.ToString("yyyy_MM_dd___HH_mm_ss"), ".csv"); var csv = new SNC.File(CurrentForm); csv.Name = fileName; csv.Binary = new BinaryData(); csv.Binary.FileName = fileName; csv.Binary.ContentType = "application/vnd.ms-excel"; string text = GetCSV(CurrentForm); MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream, Encoding.GetEncoding("windows-1250")); writer.Write(text); writer.Flush(); csv.Binary.SetStream(stream); csv.Save(); //HttpContext.Current.Response.ClearHeaders(); //HttpContext.Current.Response.Clear(); //HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + csv.Name); //HttpContext.Current.Response.AddHeader("Content-Length", csv.Binary.Size.ToString()); //HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; //HttpContext.Current.Response.Write(new BinaryReader(csv.Binary.GetStream()).ReadString()); //HttpContext.Current.Response.End(); (this.Parent as SingleContentView).OnUserAction(sender, "cancel", "Click"); } }
private void CreateOrModifyCacheFile(BinaryData cacheBinary, bool compress) { SN.File f = null; MemoryStream cacheStream = new MemoryStream(); if (compress) { GZipOutputStream gzipStream = new GZipOutputStream(cacheStream); byte[] buff = Encoding.ASCII.GetBytes(this._content.ToCharArray()); gzipStream.Write(buff, 0, buff.Length); gzipStream.Flush(); gzipStream.Close(); // set compressed binary byte[] compressedData = cacheStream.ToArray(); cacheBinary.SetStream(new MemoryStream(compressedData)); } else { cacheBinary.SetStream(Tools.GetStreamFromString(_content)); } // gets cache file or creates a new one, the new stream will be saved in both cases if (!Node.Exists(FullCacheFilePath)) { f = SN.File.CreateByBinary(this.CacheFolder, cacheBinary); f.Name = _cacheFile; } else { f = Node.Load <SN.File>(this.FullCacheFilePath); f.Binary = cacheBinary; } f.Save(); }
private void importFromFile() { string error = String.Empty; string fileName = "portlets.xml"; var portletContentPath = RepositoryPath.Combine(pageNode.Path, fileName); snc.File xmlFile = Node.LoadNode(portletContentPath) as ContentRepository.File; if (xmlFile != null) { try { Stream binstream = xmlFile.Binary.GetStream(); XmlDocument newXml = new XmlDocument(); using (XmlReader reader = XmlReader.Create(binstream)) { newXml.Load(reader); } pageNode.SetPersonalizationFromXml(HttpContext.Current, newXml, out error); } catch (Exception e) { Logger.WriteException(e); } } }
protected static XmlDocument GetXmlDocument(string ConfigPath) { ContentRepository.File configNode = Node.Load <ContentRepository.File>(ConfigPath); if (configNode == null) { return(null); } var configXml = new XmlDocument(); using (TextReader reader = new StreamReader(configNode.Binary.GetStream())) { configXml.LoadXml(reader.ReadToEnd()); } return(configXml); }
private void exportToFile() { string fileName = "portlets.xml"; snc.File newPortletInfoFile = null; BinaryData newPortletInfoBinary = null; var portletContentPath = RepositoryPath.Combine(pageNode.Path, fileName); if (NodeHead.Get(portletContentPath) == null) { newPortletInfoFile = new snc.File(pageNode); newPortletInfoBinary = new BinaryData(); } else { newPortletInfoFile = Node.Load <snc.File>(portletContentPath); newPortletInfoBinary = newPortletInfoFile.Binary; } newPortletInfoFile.Name = fileName; newPortletInfoFile.Hidden = true; MemoryStream stream = new MemoryStream(); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create(stream, settings)) { if (pageXml == null) { loadXml(); } pageXml.WriteTo(writer); writer.Flush(); newPortletInfoBinary.SetStream(stream); newPortletInfoFile.Binary = newPortletInfoBinary; newPortletInfoFile.Save(); } }
internal static void SavePortletDefinition(WebPart webPart, string contentString) { if (webPart == null) { throw new ArgumentNullException("webPart"); } if (String.IsNullOrEmpty(contentString)) { throw new ArgumentException("contentString"); } var currentPage = Portal.Page.Current; var newPortletInfoFileName = String.Concat(webPart.ID, "$", webPart.Zone.ID, PortletInfoFileNameExtension); SNC.File newPortletInfoFile = null; BinaryData newPortletInfoBinary = null; var portletContentPath = RepositoryPath.Combine(currentPage.Path, newPortletInfoFileName); if (NodeHead.Get(portletContentPath) == null) { newPortletInfoFile = new SNC.File(currentPage); newPortletInfoBinary = new BinaryData(); } else { newPortletInfoFile = Node.Load <SNC.File>(portletContentPath); newPortletInfoBinary = newPortletInfoFile.Binary; } var contentStream = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(contentString)); newPortletInfoBinary.SetStream(contentStream); newPortletInfoFile.Name = newPortletInfoFileName; newPortletInfoFile.Binary = newPortletInfoBinary; newPortletInfoFile.Save(); }
public override VirtualFile GetFile(string virtualPath) { var currentPortalContext = PortalContext.Current; // office protocol: instruct microsoft office to open the document without further webdav requests when simply downloading the file // webdav requests would cause an authentication window to pop up when downloading a docx if (HttpContext.Current != null && HttpContext.Current.Response != null) { if (Repository.DownloadExtensions.Any(extension => virtualPath.EndsWith(extension))) { //we need to do it this way to support a 'download' query parameter with or without a value var queryParams = HttpContext.Current.Request.QueryString.GetValues(null); var download = HttpContext.Current.Request.QueryString.AllKeys.Contains("download") || (queryParams != null && queryParams.Contains("download")); if (download) { var fName = string.Empty; if (currentPortalContext != null && currentPortalContext.IsRequestedResourceExistInRepository) { // look for a content var node = Node.LoadNode(virtualPath); if (node != null) { fName = DocumentBinaryProvider.Current.GetFileName(node); } } else { // look for a file in the file system fName = Path.GetFileName(virtualPath); } HttpHeaderTools.SetContentDispositionHeader(fName); } } } if (DiskFSSupportMode == DiskFSSupportMode.Prefer && base.FileExists(virtualPath)) { var result = base.GetFile(virtualPath); //let the client code log file downloads if (PortalContext.Current != null && PortalContext.Current.ContextNodePath != null && string.Compare(virtualPath, PortalContext.Current.ContextNodePath, StringComparison.Ordinal) == 0) { File.Downloaded(virtualPath); } return(result); } // Indicates that the VirtualFile is requested by a HttpRequest (a Page.LoadControl also can be a caller, or an aspx for its codebehind file...) var isRequestedByHttpRequest = (HttpContext.Current != null) && (string.Compare(virtualPath, HttpContext.Current.Request.Url.LocalPath, StringComparison.InvariantCultureIgnoreCase) == 0); if (isRequestedByHttpRequest && currentPortalContext.IsRequestedResourceExistInRepository) { return(new RepositoryFile(virtualPath, currentPortalContext.RepositoryPath)); } else if (IsFileExistsInRepository(virtualPath)) //OPT: nem kéne még egyszer megnézni, hogy bent van-e... { return(new RepositoryFile(virtualPath, virtualPath)); } else if (IsFileExistsInAssembly(virtualPath)) { return(new EmbeddedFile(virtualPath)); } else { // Otherwise it may exist in the filesystem - call the base return(base.GetFile(virtualPath)); } }