private void getFiles(string relativePath) { string siteId = null; bool isTemplate = BuilderApplication.Instance.CurrentSite == null; if (isTemplate) { if (BuilderApplication.Instance.CurrentTemplate != null) { siteId = BuilderApplication.Instance.CurrentTemplate.ID; } else if (BuilderApplication.Instance.Templates.Count > 0) { siteId = BuilderApplication.Instance.Templates[0].ID; } } else { siteId = BuilderApplication.Instance.CurrentSite.ID; } if (string.IsNullOrEmpty(siteId)) { return; } RelativeUrl = relativePath; if (Files.Items != null) { Files.Items.Clear(); } btnOk.IsEnabled = false; FileExplorerClient client = WCFProxyFactory.CreateFileExplorerProxy(); client.GetFilesCompleted += new EventHandler <GetFilesCompletedEventArgs>(client_GetFilesCompleted); showHideProgressBar(true); Dispatcher.BeginInvoke(() => { client.GetFilesAsync(siteId, isTemplate, relativePath, FileExtensions); }); }
private void Upload_Click(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog() { Multiselect = false, Filter = "Image Files|*.png;*.jpg;*.jpeg", }; if (openDialog.ShowDialog() == true) { FileInfo selectedFile = openDialog.File; if (selectedFile == null) { return; } byte[] fileBuffer = null; try { using (FileStream strm = openDialog.File.OpenRead()) { selectedFile = openDialog.File; using (BinaryReader rdr = new BinaryReader(strm)) { fileBuffer = rdr.ReadBytes((int)strm.Length); } } if (fileBuffer != null) { string siteId = null; bool isTemplate = BuilderApplication.Instance.CurrentSite == null; if (isTemplate) { if (BuilderApplication.Instance.CurrentTemplate != null) { siteId = BuilderApplication.Instance.CurrentTemplate.ID; } else if (BuilderApplication.Instance.Templates.Count > 0) { siteId = BuilderApplication.Instance.Templates[0].ID; } } else { siteId = BuilderApplication.Instance.CurrentSite.ID; } if (string.IsNullOrEmpty(siteId)) { return; } showHideProgressBar(false); FileExplorerClient client = WCFProxyFactory.CreateFileExplorerProxy(); client.UploadFileToSiteCompleted += new EventHandler <UploadFileToSiteCompletedEventArgs>(client_UploadFileToSiteCompleted); client.UploadFileToSiteAsync(siteId, isTemplate, RelativeUrl, selectedFile.Name, fileBuffer.ToArray(), "image/png"); } } catch (Exception ex) { Logger.Instance.LogError(ex); } } }