Posts Tagged ‘BrowserIntegration’
18
Nov

Calling Mailto using JavaScript

2 Comments » Popularity: 4%

This is a code snippet showing how you may call the “mailto” to open your mail program.

Calling Mailto using JavaScript

View Demo: New Window
Calling mailto via Javascript:
private void SendEmail(string email, string subject, string body)
{
     Uri uri = new Uri(String.Format("mailto:{0}?subject={1}&body={2}", email, subject, body));
     System.Windows.Browser.HtmlPage.Window.Navigate(uri);
}
29
Sep

Open/Navigate to an external link

Post a comment » Popularity: 5%

The code helps to you navigate to an external link or website using code and HyperlinkButton. Please not that if you are running the application in out of browser mode, the C# will not work . In such case, you have to use HyperlinkButton to open an external link.

Open external link

Open link in c#:
using System.Windows.Browser;
private void Button_Click(object sender, RoutedEventArgs e)
{
    Uri uri = new Uri("http://silverlike.net", UriKind.Absolute);
    HtmlPage.PopupWindow(uri, "_blank", new HtmlPopupWindowOptions() { Width = 800, Height = 600};
    // or
    HtmlPage.Window.Navigate(uri, "_blank");
}
Open link using HyperlinkButton:
<HyperlinkButton  Content="Silverlike" NavigateUri="http://silverlike.net" TargetName="_blank"/>
28
Sep

Integrate with Browser Cookie

Post a comment » Popularity: 3%

Integrate with the browser cookie for saving and accessing data in the cookie.

Integrate with Browser Cookie

Get and Set Cookie:
// sample usage
CookieManager.SetCookie("key", "value", TimeSpan.FromSeconds(3600));
string value  = CookieManager.GetCookie("value");

// cookie manager class
public class CookieManager
    {

        public static void SetCookie(string key, string val, TimeSpan? expires)
        {

            SetCookie(key, val, expires, null, null, false);
        }

        public static void SetCookie(string key, string val, TimeSpan? expires, string path, string domain, bool secure)
        {

            StringBuilder fullCookie = new StringBuilder();
            fullCookie.Append(string.Concat(key, "=", val));

            if (expires.HasValue)
            {

                DateTime expire = DateTime.UtcNow + expires.Value;
                fullCookie.Append(string.Concat(";expires=", expire.ToString("R")));
            }

            if (path != null)
            {

                fullCookie.Append(string.Concat(";path=", path));
            }

            if (domain != null)
            {

                fullCookie.Append(string.Concat(";domain=", domain));
            }

            if (secure)
            {

                fullCookie.Append(";secure");
            }

            HtmlPage.Document.SetProperty("cookie", fullCookie.ToString());
        }

        public static string GetCookie(String key)
        {
            String[] cookies = HtmlPage.Document.Cookies.Split(';');
            String result = (from c in cookies let keyValues = c.Split('=') where
                                 keyValues.Length == 2 && keyValues[0].Trim() == key.Trim()
                             select keyValues[1]).FirstOrDefault();
            return result;
        }

        public static void DeleteCookie(String key){
            DateTime expir =DateTime.UtcNow -TimeSpan.FromDays(1);
            string cookie =String.Format("{0}=;expires={1}",
            key, expir.ToString("R"));
            HtmlPage.Document.SetProperty("cookie", cookie);
        }

        public static bool Exists(String key, String value)
        {
            return HtmlPage.Document.Cookies.Contains(String.Format("{0}={1}", key, value));
        }
    }