Posts
[C#]Decode Unicode Character
if (!match.Success) return string.Empty; var code = match.Groups["code"].Value; int value = Convert.ToInt32(code, 16); return ((char)value).ToString(); }</pre>
read morePosts
[C#]DropBox開發系列 - 使用DropNet上傳檔案至DropBox
... var selectedNode = treeView1.SelectedNode; if (selectedNode == null) return; var metaData = selectedNode.Tag as MetaData; if (metaData == null) return; if (!metaData.Is_Dir) { MessageBox.Show("Please select a folder first."); return; } if (tbxFile.Text.Length == 0) { MessageBox.Show("Please select a file to upload first."); return; } if (!File.Exists(tbxFile.Text)) { MessageBox.Show("File not found."); return; } m_DropNetClient.UploadFile(metaData.Path, Path.GetFileName(tbxFile.Text), File.ReadAllBytes(tbxFile.Text)); ...</pre></div> namespace DropNetDemo { public partial class Form1 : Form { #region Var private DropNetClient _dropNetClient; #endregion
read morePosts
[C#]DropBox開發系列 - 使用DropNet下載DropBox內存放的檔案
var metaData = selectedNode.Tag as MetaData; if(metaData == null) return; using (var saveFileDialog = new SaveFileDialog()) { saveFileDialog.FileName = metaData.Name; if(saveFileDialog.ShowDialog() == DialogResult.OK) { var fileData = m_DropNetClient.GetFile(metaData.Path); File.WriteAllBytes(saveFileDialog.FileName, fileData); } } ...</pre></div> namespace DropNetDemo { public partial class Form1 : Form { #region Var private DropNetClient _dropNetClient; #endregion
#region Private Property private DropNetClient m_DropNetClient { get { return _dropNetClient ?? (_dropNetClient = new DropNetClient(tbxAppKey.Text, tbxAppSecret.Text)); } set { _dropNetClient = value; } } #endregion public Form1() { InitializeComponent(); } private void SetSecretAndToken(string secret, string token) { Settings.
read morePosts
[C#]DropBox開發系列 - 使用DropNet進行DropBox的OAuth認證
... dialog.Controls.Add(browesr); dialog.ShowDialog(); ... }</pre></div> if (DoOAuth(callbackUrl, cancelCallbackUrl, size) == DialogResult.OK) { var accessToken = m_DropNetClient.GetAccessToken(); } ... private DialogResult DoOAuth(string callbackUrl, string cancelCallbackUrl, System.Drawing.Size size) { using (var dialog = new Form()) { var browesr = new WebBrowser() { Dock = DockStyle.Fill }; m_DropNetClient.GetToken(); var authUrl = m_DropNetClient.BuildAuthorizeUrl(); browesr.Navigated += (s, ex) => { var url = ex.Url.ToString(); if (url.Equals(callbackUrl)) { dialog.DialogResult = DialogResult.OK; } else if (url.Equals(cancelCallbackUrl)) { dialog.
read morePosts
[C#]DropBox開發系列 - 使用DropNet進行DropBox的二次登入
return; } ... if (DoOAuth(callbackUrl, cancelCallbackUrl, size) == DialogResult.OK) { var accessToken = m_DropNetClient.GetAccessToken(); Properties.Settings.Default.SECRET = accessToken.Secret; Properties.Settings.Default.TOKEN = accessToken.Token; Properties.Settings.Default.Save(); }</pre></div> namespace DropNetDemo { public partial class Form1 : Form { #region Var private DropNetClient _dropNetClient; #endregion
#region Private Property private DropNetClient m_DropNetClient { get { return _dropNetClient ?? (_dropNetClient = new DropNetClient(tbxAppKey.Text, tbxAppSecret.Text)); } set { _dropNetClient = value; } } #endregion public Form1() { InitializeComponent(); } private void SetSecretAndToken(string secret, string token) { Settings.
read morePosts
[C#]DropBox開發系列 - 使用DropNet遍巡DropBox內存放的檔案
FillTreeView(); return; } var callbackUrl = "https://www.dropbox.com/1/oauth/authorize"; var cancelCallbackUrl = "https://www.dropbox.com/home"; var size = new Size(1024, 600); if (DoOAuth(callbackUrl, cancelCallbackUrl, size) == DialogResult.OK) { var accessToken = m_DropNetClient.GetAccessToken(); Properties.Settings.Default.SECRET = accessToken.Secret; Properties.Settings.Default.TOKEN = accessToken.Token; Properties.Settings.Default.Save(); FillTreeView(); } }
private void FillTreeView() { treeView1.Nodes.Clear(); var metaData = m_DropNetClient.GetMetaData("/");
FillDirOrFileToTreeView(null, metaData); }
private void FillDirOrFileToTreeView(TreeNode parentNode, MetaData metaData) { if (metaData.Contents == null) return;
var nodes = (parentNode == null) ? treeView1.
read morePosts
[C#]Export PowerPoint file to photos
var ppt = application.Presentations.Open(file, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse); var index = 0; var fileName = Path.GetFileNameWithoutExtension(file); foreach (Slide slid in ppt.Slides) { ++index; slid.Export(Path.Combine(outputPath, string.Format("{0}{1}.jpg", fileName, index)), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); } ppt.Close(); application.Quit(); GC.Collect(); }</pre></div> void ConvertPptToJpg(string file, string outputPath) { Type t = Type.GetTypeFromProgID("PowerPoint.Application"); object o = Activator.CreateInstance(t); object p = t.InvokeMember( "Presentations", BindingFlags.Public | BindingFlags.GetProperty, null, o, null, null); Type t2 = p.GetType(); object ppt = t2.InvokeMember("Open", BindingFlags.Public | BindingFlags.
read morePosts
[C#]Json.NET - A high performance Json library
public String NickName { get; set; } public DateTime Birthday { get; set; } public int Age { get { return (int)((DateTime.Now - Birthday).TotalDays / 365); } } }</pre></div> Person Larry = new Person { Name = "Larry Nung", NickName = "蹂躪", Birthday = new DateTime(1980,4,19) }; var json = JsonConvert.SerializeObject(Larry, Formatting.Indented); ... var person = JsonConvert.DeserializeObject<Person>(json); ...</pre></div> public String NickName { get; set; } public DateTime Birthday { get; set; } public int Age { get { return (int)((DateTime.
read morePosts
[C#]Json.NET - Reducing Serialized JSON Size
public String NickName { get; set; } public DateTime Birthday { get; set; } public int Age { get { return (int)((DateTime.Now - Birthday).TotalDays / 365); } } }
Person Larry = new Person { Name = “Larry Nung”, Birthday = new DateTime(1980,4,19) };
var json = JsonConvert.SerializeObject(Larry, Formatting.Indented);
Console.WriteLine(json);
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] public String NickName { get; set; } ... public bool ShouldSerializeNickName() { return !string.IsNullOrEmpty(NickName); } }</pre></div> protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) { JsonProperty property = base.
read more