/
publishStory.xaml.cs
executable file
·122 lines (87 loc) · 3.17 KB
/
publishStory.xaml.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using $safeprojectname$.HelperClasses;
namespace $safeprojectname$
{
public partial class Page2 : PhoneApplicationPage
{
public Page2()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
Page1 appObject = new Page1();
Uri uri = new Uri(App.imageSelected);
BitmapImage bmp = new BitmapImage(uri);
publishImage.Source = bmp;
title.Text = App.titleEntered;
}
private WebClient webClientObj;
private void button3_Click(object sender, RoutedEventArgs e)
{
if (webClientObj == null)
{
webClientObj = new WebClient();
webClientObj.UploadStringCompleted += new UploadStringCompletedEventHandler(UploadString);
}
try
{
// Form a string of the form
// access_token=765985689876764879857509439&caption=aaaaaaaaa&message=aaaaaaaa&picture=aaaaaaa
string publishString = "access_token=" + App.AccessToken;
if (!string.IsNullOrEmpty(App.titleEntered))
{
publishString += "&caption=" + HttpUtility.UrlEncode(App.titleEntered);
}
if (!string.IsNullOrEmpty(message.Text))
{
publishString += "&message=" + HttpUtility.UrlEncode(message.Text);
}
if (!string.IsNullOrEmpty(App.imageSelected))
{
publishString += "&picture=" + HttpUtility.UrlEncode(App.imageSelected);
}
// Send the message title and image to facebook wall
webClientObj.UploadStringAsync(FBUris.GetPostMessageUri(), "POST", publishString);
}
catch (Exception obj)
{
result.Text = "post to wall failed!" + obj.Message;
}
// Navigate back to your application
NavigationService.Navigate(new Uri("/VishakW7App.xaml", UriKind.Relative));
}
void UploadString(object sender, UploadStringCompletedEventArgs e)
{
if (e.Error != null)
{
result.Text = "Post to wall failed!";
return;
}
try
{
result.Text = "Successfully posted to wall!";
}
catch (Exception obj)
{
result.Text = "Post to wall failed!" + obj.Message;
}
}
private void button2_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/VishakW7App.xaml", UriKind.Relative));
}
}
}