|
Hi all,
I want to download xml or any other file from physical location like C:\Documents and Settings\All Users\Documents\Test.xml and open a Save Dialog box to allow user to save it in desired location
Is it possible in Silverlight 2.0?
Can we do it in xaml.cs file?
If yes then plz share the code with me.....
Its very urgent.........
Thanks in advance,
|
|
|
|
|
salon wrote: Is it possible in Silverlight 2.0?
Opening a file you can do using the OpenFileDialog class, so the user
effectively needs to give permission first.
Saving a file, no, not in Silverlight 2.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Another option (not elegant but works) could be to perform a ping pong using services:
- Send your file to the server again using a WCF service, store it in session.
- Call a javascript method from SL that will make a request to a custom HTTP hanlder.
- That custom HTTP hanlder would return the file that was in session as an attachment (first time the nasty bar from IE would appear... you are going to download something...).
In my application I needed to export a DB Diagram to JPEG and to perform an export as well to an HTML report, I used that approach (ping pong ), I could set an attribute (attachment) and IE would ask me to save the JPEG as a file.
If you want to take a look at how it behaves:
http://www.dbschemaeditor.com
HTH Braulio
/// -------------------------
Braulio Díez
DBSchemaEditor.com
Free Silverlight based DB Schema Modeling Tool
/// -------------------------
|
|
|
|
|
If you don't mind !
Can you share the code/link to solution so that I get a clear picture of the entire thing?
I have searched for the above solution but not getting any way.............
Please help me....
|
|
|
|
|
I don't have alink with the whole solution, but the pieces and what I implemented on my project.
Let's go step by step:
About the solution:
It's a workaround, SL cannot do that, what we do then is to workaround it using ASP .net / Javascript (in ASP .net it's possible to return a file to client as an attachment).
In my case:
--> I have an XML file on my client side (that represents the database diagram), it could be whatever that can be serializable.
--> I have an WCF service that accepts as input parameter that XML file, I send a call from SL to the service (if you have question on this give me a shout and will try to find some tutorial about how to call services from SL).
--> This service that I'm calling inherits the context from the ASP .net application, that is, we have the ASP .net session available, to enable this you only have to add to the header of your service class:
<br />
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />
public class RenderService<br />
--> In my case I stored the XML file in a session variable in the server (so for that user we get the file in his session / memory).
--> Once the Silverlight receives the callback from the service call (the service has been called successfully), I call from SL a javascript method:
public void ShowDiagramImageRenderPopup()
{
System.Windows.Browser.HtmlPage.Window.CreateInstance("showReportDiagramPopup");
}
--> This javascript methods opens a popup that points to a URL (if I want it to download a file I just have to open a page in the same navigator, the only thing is that the custom HTTP Handler must return an "attacment").
function showReportDiagramPopup() {
window.open("DiagramRenderPopup.aspx", "DatabaseDiagram", "scrollbars=yes, width=800,height=600", false);
}
--> Ok, now let's go for the CUstom HTTP Hanlder "DiagramImageHandler.ashx", the main code snippet that does the trick
public void ProcessRequest(HttpContext context)
{
EntityExportDiagram exportDiagram = (EntityExportDiagram)HttpContext.Current.Session["printreport"];
Bitmap bitmap = new Bitmap(width, height,
PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
SolidBrush br = new SolidBrush(Color.White);
g.FillRectangle(br, 0, 0, width, height);
br.Dispose();
(...)
g.Dispose();
context.Response.ContentType = "image/jpeg";
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
bitmap.Save(memoryStream, ImageFormat.Jpeg);
context.Response.AddHeader("Content-Length", memoryStream.Length.ToString());
memoryStream.WriteTo(context.Response.OutputStream);
context.Response.End();
bitmap.Dispose();
context.Response.Flush();
context.Response.Close();
}
--> Then once the page is called, in my case a popup is shown with the diagram exported as JPEG, in your case (setting the attachment file) you will get a download / save file (watch out here, first time users will get a nasty IE warning and the SL application will reset, security stuff ).
HTH
Braulio
PS.: Hope to get sometime some day and write a complete sample about this.
/// -------------------------
Braulio Díez
DBSchemaEditor.com
Free Silverlight based DB Schema Modeling Tool
/// -------------------------
|
|
|
|
|
so... what used to be in app.config should now be in xaml this point forward?
I know for one the user interface is in xaml represented pretty much like HTML/ASP.NET tags, and we should also include resources in xaml. What about other configuration?
One of the article I stumbled upon ...
<br />
string xaml = @"<string assembly="" mscorlib=""><br />
<string xmlns=""><br />
hello world</string></string>";<br />
byte[] xaml_data = System.Text.Encoding.ASCII.GetBytes(xaml);<br />
System.IO.MemoryStream xaml_stream = new System.IO.MemoryStream(xaml_data);<br />
string xaml_object = (string)System.Windows.Markup.XamlReader.Load(xaml_stream);<br />
Console.WriteLine(xaml_object);<br />
Using XAML for Custom Application Configuration [^]
So seems like you can resurrect an object from xaml file - what I don't see is how it's superior to "add key=xxxx value=xxx" in old app.config or spring.net dependency injection.
a good article on this for reference? I've stumbled across couple but.. I want to answer key question - "Do I want to put app.config in xaml carrying forward?"
dev
modified on Friday, April 17, 2009 6:04 AM
|
|
|
|
|
devvvy wrote: I want to answer key question - "Do I want to put app.config in xaml carrying forward?"
Short answer - it depends. If it's something that fits neatly into app.config, e.g. a connection string, then leave it there. If it's something that you need the power of XAML for, then put it in the XAML.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
but xaml is primarily intended for declarative UI construction - not a place to store application config right?
But is xaml going to become more a more popular as a place to store config information as well? (if so there must be reasons/features compelling enuf...)
dev
|
|
|
|
|
devvvy wrote: but xaml is primarily intended for declarative UI construction
That's a common mistake. XAML is used OFTEN to construct UIs, but it's really just a mechanism to compile XML - that's the declarative portion. In .NET 4, XAML is going to become a first class citizen, i.e. there will be a System.Xaml.dll.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
do you use xaml for storage of config information yourself now?
dev
|
|
|
|
|
Nope. That's not to say I won't - I just don't yet.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Sheesh, I'm glad I read this thread. I'd not even remotely thought of XAML for storing config ...
|
|
|
|
|
so... can we simply write one set of Xaml to represent UI for a WPF app.
<StackPanel x:Name="sp1" Orientation="Vertical">
<StackPanel.Resources>
<local:LocalClass x:Key="localClass1" AnIntProp="5"/>
</StackPanel.Resources>
... more stuff..
</StackPanel>
Then just port it (i.e. use same Xaml) to Silverlight?
Can we do that?
I'm a silverlight newbie.
thanks
dev
|
|
|
|
|
Try it. Unless you use WPF-specific features, the XAML will work in both.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
dear Friend.
my silverlight project run successfully from solution.but i make setup of the project and deploy it.Then it's not working and Web Service is not found .after that i have change my Service references.clintconfig Endpoint setup name in address(FileConverstionBeta11) then it run successfully and i also add the clientaccesspolicy.xml with the project
After change EndPoint(its not working from local host):-
<client>
(endpoint address="http://localhost/FileConverstionBeta11/WSFileConversion.asmx"
binding="basicHttpBinding" bindingConfiguration="WSFileConversionSoap"
contract="ServiceReference1.WSFileConversionSoap" name="WSFileConversionSoap" /)
Before change EndPoint(its not working from local host) :-
<client>
(endpoint address="http://localhost/FileConverstion/WSFileConversion.asmx"
binding="basicHttpBinding" bindingConfiguration="WSFileConversionSoap"
contract="ServiceReference1.WSFileConversionSoap" name="WSFileConversionSoap" /)
and my application name is :-FileConverstion
then how to run application successfully without change of Service references.clintconfig Endpoint.Pleas help me to resolved this problem
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
Eventure Technology
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Piyush Vardhan Singh wrote: how to run application successfully without change
You can't. You have to change the endpoint address to match the host.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
how it possible to change endpoint the address for every client...
Piyush Vardhan Singh
p_vardhan14@rediffmail.com
Eventure Technology
http://holyschoolofvaranasi.blogspot.com
http://holytravelsofvaranasi.blogspot.com
|
|
|
|
|
Typically servers are set up so they are reachable using the same address
from anywhere. For example, http://www.codeproject.com
Your server-side endpoint address is going to need to be different when
the app is deployed. The client side address needs to be changed to reach the
server at its deployed location.
I have no idea how you've deployed your service and to what type server, but
for example "http://localhost..." won't be in the address of a service endpoint
deployed on IIS.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I have a treeview in expander in my wpf project..
I am using hierarchical datatemplate (which have arrow image and textblock) for treeview databinding.
I am using style triggers for changing selected node's fonts to bold..
Now upto this all things working fine, but after selecting particular node(either child or parent) when i collapsed my expander control and expand it again, background for textblock will be gray..
Any idea??
|
|
|
|
|
Last selected Item of treeview control will display the gray color, on expand of expander for the reason it represent disabled selection.
Select an item in treeviewcontrol, and then click outside the preview of treeviewcontrol to trigger lost focus of treeviewcontrol, the selected item will be gray.
<Style x:Key="TreeViewItemItemTemplateStyle" TargetType="{x:Type TreeViewItem}">
<Style.Resources>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue" />
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightGray" />
</Style.Resources>
</Style>
you can override the gray color by applying the color you want for not focussed style.
|
|
|
|
|
If anyone can tell me how to place images in a dll and access them from a WPF exe, I would appreciate it. Everything I've tried online, I get error messages that the file cannot be found.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I've just created a class library and added a resource file (from the project properties) and set its Access Modifier to public. The resource contained a PNG file. In the WPF project, I added references to the class library and System.Drawing (since it returns Bitmap).
Then loaded the image like this, var img = ClassLibrary1.Properties.Resources.Image1;
You can then use System.Windows.Interop.Imaging to convert to BitmapSource.
If you're talking about resource dictionaries, I found this[^] and I'll try tomorrow to see if there is another way to do it.
Eslam Afifi
|
|
|
|
|
Thank you. I've tried doing it the WPF way and it plain does not work, so I expect this is the sort of thing I am going to end up doing. Just so ugly to have to convert an image to an image ( as it where ) because the whole setup is so badly designed. I wonder if it's even possible to load these images from a dll in XAML, every example I've seen online, plain does not work.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
I have managed to do it in XAML.
In the class library, add a XAML file (or drag and drop from an existing WPF project). Don't forget to set its Build Action to Page.
<ResourceDictionary x:Class="Resource1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<BitmapImage x:Key="img" UriSource="Resources\Image1.png" />
<SolidColorBrush x:Key="greenBrush" Color="Green" />
</ResourceDictionary>
And add a class in the library, the code is similar to the one found in App.g.cs
public partial class Resource1 : ResourceDictionary
{
private bool _contentLoaded;
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent()
{
if (_contentLoaded)
return;
_contentLoaded = true;
System.Uri resourceLocater = new System.Uri("ClassLibrary1;component/Dictionary1.xaml", System.UriKind.Relative);
System.Windows.Application.LoadComponent(this, resourceLocater);
}
public Resource1()
{
InitializeComponent();
}
}
Add a reference to the library in the WPF project, and add the resource dictionary anywhere (for example Application.Resources. Don't forget to add the XML namespace.
<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lib="clr-namespace:ClassLibrary1;assembly=ClassLibrary1"
StartupUri="Window1.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<lib:Resource1 />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Now you can use it in XAML just like any resource dictionary.
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Background="{StaticResource greenBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Image Source="{StaticResource img}" />
</Grid>
</Window>
And also access them from code,
var brush = this.TryFindResource("greenBrush");
var imgWPFStyle = Application.Current.TryFindResource("img");
And I agree with you that the InitializeComponent code should be automatically generated by visual studio. But until they add that feature, it's not hard to copy and paste that code snippet.
And you're welcome.
Eslam Afifi
modified on Friday, April 17, 2009 3:53 PM
|
|
|
|
|
Hi, Cristian!
Usually the best way to cure this sort of errors is to open the assembly you are loading resource from in the Refelctor and to see at the resource name. The resource name in your code must match exactly the name the Reflector will show. It will be all lowercase and can be qualified by the directory name where your resource is stored in the resource assembly.
I hope when requesting the resource you reference the assembly which contains this resource.
Regards,
Oleg V. Polikarpotchkin
ovp
|
|
|
|