WebClient.DownloadProgressChanged not working? - windows-phone-7

I am using Windows Phone to download a file with a WebClient. The DownloadProgressChanged event does not work. It fires only once, returning a value of "4923206" for DownloadProgressChangedEventArgs.BytesRecieved. My code is:
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadProgressChanged += wbchange;
wb.OpenReadAsync(new Uri("http://sohowww.nascom.nasa.gov/data/LATEST/current_eit_304small.gif"));
}
private void wbchange(object sender, DownloadProgressChangedEventArgs e)
{
MessageBox.Show(e.BytesReceived.ToString()); (obviously in the end I will not be showing a message at every change)
}
What is wrong with this?

It's working absolutely fine, it just happens to have downloaded all the bytes on the first DownloadProgressChanged invoke.
If you read the documentation you'll see that this is the expected behaviour.

Related

Listening to the item move event with outlook add-in

I want to do some functionality when user moves a mail item (from a folder to another folder). So I want to capture the mail item move event with the outlook add-in.
I think this should be possible with following event handlers,
MAPIFolderEvents_12_BeforeItemMoveEventHandler
ItemsEvents_ItemRemoveEventHandler
I tried with both of the above event handles. But they didn’t work for me. Could someone provide an example. Here is the code for MAPIFolderEvents_12_BeforeItemMoveEventHandler.
Outlook.Folder fldr;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
fldr = (Outlook.Folder)Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderTasks);
fldr.BeforeItemMove += new Microsoft.Office.Interop.Outlook.
MAPIFolderEvents_12_BeforeItemMoveEventHandler
(Folder_BeforeItemMove);
}
private void Folder_BeforeItemMove(object anItem, MAPIFolder aMoveToFolder, ref bool Cancel)
{
Outlook.MailItem mailItem = (anItem as Outlook.MailItem);
//Do other stuff
}
The object that raises the events (fldr) must be declared on the class level instead of local to avoid being released by the Garbage Collector.
Had a similar requirement for iterating through MailFolders.
So please try as below:
Outlook.MAPIFolder mapifldr;
Outlook.Folder fldr;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
mapifldr=Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderTasks);
fldr = (Outlook.Folder) Application.GetNamespace("MAPI").GetFolderFromID(mapifldr.EntryID);
fldr.BeforeItemMove += new Microsoft.Office.Interop.Outlook.
MAPIFolderEvents_12_BeforeItemMoveEventHandler
(Folder_BeforeItemMove);
}
This is a very old post but hope it saves time for others.

Synchronous Call in Windows Phone 7

I know that I cannot make a true synchronous call in Windows Phone 7. However, I'm trying to at least block the threads from processing until the async call is made or there is a timeout. I've tried the following, but it seems like my app just ignores it, abandons the call, and doesn't return back. Any ideas why?
I'm trying to update a value using a Value Converter during binding.
public ManualResetEvent _event;
public void GetSync()
{
_event = new ManualResetEvent(false);
var wc = new WebClient();
wc.OpenReadCompleted += new OpenReadCompletedEventHandler(ReadCompleted);
wc.OpenReadAsync(new Uri("My URL"));
// block until async call is complete
_event.WaitOne(5000);
}
private void ReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
var serializer = new XmlSerializer(typeof(MyFormatter));
// The property below is accessed back in the Value Converter for binding
StronglyTypedObject = (StObject)serializer.Deserialize(e.Result);
_event.Set();
}

Not able to insert data into remote mySQL Database using PHP

I am trying to insert data into remote MySQL database using WP7 app but values does not get inserted, PHP file works perfect as my queries are getting inserted into DB using JAVA(Android). As I am new to C# I am facing this challenge.
The code goes like this:-
public MainPage()
{
InitializeComponent();
textBox1.Text = "http://www.abc.com/xyz/user_master.php?Email=abc#xyz.com&Username=abc&Password=xyzz&Phone=98989";
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
textBlock2.Text = e.Result;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri(textBox1.Text));
}
Please correct me.
The problem is that you are using "DownloadStringAsync" which sends a GET and so you POST variable is not filled in PHP, you have to use "UploadStringAsync".
For now I can not tell you how the body has to look like... Until now I have used JSON all the time. Would be nice if you could post it here to let me know when you got it ;)
update
Ah, to slow =(
Could you please still post how your message body looks like!

Get response from web browser for windows phone 'mango'

I m my application I want to use Webbrowser which will be using Wifi,after the Webbrower opens the the link (task.URL) ,I want to check what is the response like whether the linked got opened or it failed.How do I do that means get the response ?
WebBrowserTask task = new WebBrowserTask();
task.URL = "https://www.goggle.com/";
task.Show();
kindly help
Thanks.
Usually, to catch this use NavigationFailed event as follow:
void WebPage_Loaded(object sender, RoutedEventArgs e)
{
this.webHome.Navigate(new Uri(www,UriKind.Absolute));
this.webHome.NavigationFailed += webHome_NavigationFailed;
}
void webHome_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
this.webHome.NavigateToString("No web page available.");
}

Passing (Asp.Net) Session variable (uploaded by uploadify) from webmethod to same page?

When i try to get uploaded filename from generic handler (upload.ashx) using session its ok, no problem. I can also use webmethod on samepage and uploadify works great, but Session["fileName"] is getting null. Is there anything wrong on my code? Do i only need to use generic handler to get filename?
[WebMethod(EnableSession = true)]
public void LoadPicture(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["fileName"] = file.FileName;
....................Some resize and save image codes.........
context.Response.Write("1");
}
catch (Exception ex)
{
context.Response.Write("0");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (_modelService = new ModelService())
{
ModelEntity _models = new ModelEntity();
......some codes....
_models.modelphoto = Session["fileName"].ToString();
_modelService.ModelAdd(_models);
}
}
Uploadify uses Flash. Flash doesn't send cookies. In ASP.NET sessions are tracked by cookies. So, no session with uploadify, sorry.

Resources