-
Notifications
You must be signed in to change notification settings - Fork 0
/
PictureFromPhone.cs
49 lines (46 loc) · 1.63 KB
/
PictureFromPhone.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Text;
using WindowsLive.Writer.Api;
using System.Windows.Forms;
using System.IO;
using System.Net;
namespace Surla.Mobi.PictureFromPhone
{
[WriterPlugin(
"E43AE20F-38C7-467D-8838-7B71C208FACE",
"Picture from Phone",
PublisherUrl = "http://surla.mobi",
Description = "Paste pictures from your phone into your blog",
HasEditableOptions = false,
Name = "Picture from Phone",
ImagePath = "phone.png"),
InsertableContentSource("Picture from phone")]
public class PictureFromPhone : ContentSource
{
public PictureFromPhone()
{
}
public override DialogResult CreateContent(IWin32Window dialogOwner, ref string content)
{
using (PictureFromPhoneForm form = new PictureFromPhoneForm())
{
form.ShowDialog(dialogOwner);
if (!string.IsNullOrEmpty(form.Uri))
{
string tempFile = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";
string tempDir = Path.GetTempPath();
Directory.CreateDirectory(tempDir);
string fullFileName = Path.Combine(tempDir, tempFile);
WebClient client = new WebClient();
client.DownloadFile(form.Uri, fullFileName);
content = "<img src=\"" + fullFileName + "\"/>";
return DialogResult.OK;
}
else {
return DialogResult.Cancel;
}
}
}
}
}