|
thanks but I found the answer!
dev
|
|
|
|
|
Hello friends,
I have a datagrid having a column name as Download and I have kept a hyperlink button for that.
On that hyperlink button click,I want to open an csv file whose path is in database.The path is like:
D:\Project\SynchModule\SynchModuleSL.Web\Pendings\new 1_2.csv
and the file does exists in Pending Folder.
How do I open that file on Hyperlink button click??
Please treat this as an urgent thread.
pls reply
Thanks
Piyush
|
|
|
|
|
Piyush Nandanwar wrote: Please treat this as an urgent thread.
Here's a friendly piece of advice: that's not the way the forums work. This is a volunteer only site - you aren't paying for support, so you get answers based on the timescales of the poster, not on any arbitraty timescale you have to work to.
Saying that, what you should look at is using the WebClient class to download the file as an asynchronous file from the server to the client (the clues to the code you need to write are all in that sentence). You do need to be aware that your web server must have permissions to read from the folder.
|
|
|
|
|
Hi Pete
Suppose,I have permissions to access the files from server.What should I write in code to open the csv file,on hyperlink button click??
|
|
|
|
|
Well, you could always google Silverlight WebClient download file and see what you get. I did say that all the clues were in my original post. In future, I'd expect you to at least try to write the code yourself - honestly, it's not that hard. As I'm in a good mood though, you're going to need a variation of this:
private void DownloadFileClick(object sender, RoutedEventArgs e)
{
var webClient = new WebClient();
webClient.OpenReadCompleted += new webClient_OpenReadCompleted;
webClient.OpenReadAsync(new Uri(the path to the url here, UriKind.Absolute));
}
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
bool? result = sfd.ShowDialog();
if (result.HasValue && result.Value == true)
{
using (var sr = new StreamReader(e.Result))
{
string str = sr.ReadToEnd();
using (var sw=new StreamWriter(sfd.OpenFile()))
{
sw.Write(str);
}
}
}
}
|
|
|
|
|
Well,I am facing an error as "Dialogs must be user-initiated."
on -- bool? result = sfd.ShowDialog(); -- line.
|
|
|
|
|
That was just an example I typed into the textbox here. Honestly, I've given you most of the code - you can sort this one out for yourself.
|
|
|
|
|
|
Hi,
In the datagrid, I would like to format the AmountPaid column to show the £ infront of it.
At present it just shows the AmountPaid figures without the £ sign.
Note that in the xaml, I have placed the following but it shows $
<DataGridTextColumn Header="Amount Paid" Width="90" Binding="{Binding AmountPaid, StringFormat={}{0:C}}"></DataGridTextColumn>
Previously in windows forms datagridview, I could get the £ sign infront of the AmountPaid by using the following c# code.
datagrid.Columns["AmountPaid"].DefaultCellStyle.Format = "C";
Any thoughts how to do this in WPF please?
Thanks
|
|
|
|
|
|
I tried placing the following line in the constructor of my window but there is an unerline error for XmlLanguagebecause it says the name XmlLanguage does not exist in the current context.
Do you see why?
Thanks
public frmStudentDetails()
{
InitializeComponent();
this.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
}
|
|
|
|
|
You need to add a reference to System.Windows.Markup .
Hope this helps
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
|
Rather than relying on the inbuilt formatter, which has a number of shortcomings with regards to internationalisation, I tend to use a custom value converter (partly because I deal with financial software a lot, where it's common to convert a negative number to sit inside brackets). This makes for a very flexible solution, and allows you to change the language format mid application with ease.
|
|
|
|
|
Do you mean like a converter class which has a method to accept the currency and return it with the £ infront of it?
|
|
|
|
|
Sort of, but it doesn't need to accept the currency - it converts to it internally, and it's capable of reacting to culture changes.
|
|
|
|
|
|
|
Hi everyone,
I'm very new to silverlight, and trying to build a custom control which is made up of a series of paths/shapes which are of varying sizes.
Is there some sort of container that exists which you can put a series of paths/shapes in, and when stretched it scales the whole lot like you'd scale a picture??
My problem is that whenever the control is resized, (e.g. while building main.xaml) my elements all scale by different amounts, because their margins are not scaled.
e.g. Say the control (200x100) consists of
A Grid (1x1) containing:
--A Large Rectangle 200 x 100 [size of entire control, margins 0]
--A Small Square 50x50 in the centre of the grid, [so margins are 75 L&R, 25 top&Bottom]
When the control is squashed to e.g. 100x50, the margins for the small square are bigger than the entire control (75L+75R = 150), so the square vanishes. Conversely, when the control is doubled in width to 400 pixels, the small square grows not by 2x, but by 5x (from 50pixels to 250 pixels), because the margins are still 150pixels total. I need these margins to scale, so when the control is half the size, so are the margins and visa versa.... Or at least something that emulates that.
I've tried trying to make the grid have a row/column for everything that needs laying out and using the 'star' system, but some of these controls will be made up of 20 or so different paths/shapes of different sizes and locations and it's beyond impractical to implement (also buggy :S ).
Surely there's some sort of container that exists which you can just put paths/shapes in, and when stretched it scales the whole lot like you'd scale a picture??
Help!
|
|
|
|
|
You might want to take a look into the viewbox. There's a really good demonstration here[^].
|
|
|
|
|
You are correct. The grid does not scale fixed margins, which makes complete sense. Using the star (*) ratios on columns and rows *does* work, but there are a few minor gotchas.
As Pete mentioned, the ViewBox will automatically scale when you resize the control, but sadly, you are going to find out that it doesn't really scale in the way that you would probably expect . The ViewBox scales *EVERYTHING*... elements, locations, fonts, etc. When you resize your control, do you really want your 1 pixel thick lines to suddenly become 5 pixels thick? If you do, then yeah, the ViewBox is the ticket. If you don't, then you need to use the Grid .
I've run into situations where I wanted to scale certain portions of the control only... take for example if you were drawing a bicycle wheel. Two circles plus a bunch of 1 pixel thick spokes for arguments sake. You'd probably want to scale the size of the two circles, but you probably would NOT want to scale the size of the spokes, you'd probably want to keep them 1 pixel thick.
If you use a ViewBox in that case, its a *MAJOR* PITA.
|
|
|
|
|
Thanks so much! I had thought of the viewbox earlier but it only accepts one item. Your reply helped me realise that that one item could, of course, be a 1x1 grid holding all of the elements...
Just for my learning's sake, if you did want to scale certain portions of the control only (e.g with your bike-wheel example) do you end up having to write your own container control?
|
|
|
|
|
First off, let me correct you on one thing that will open up your world ... there is no rule that says you can't have multiple containers in one window on top of each other. I.e. a window doesn't necessarily have to be:
<Window>
<ViewBox />
</Window>
it could also be:
<Window>
<Grid>
<ViewBox />
<Grid />
</Grid>
</Window>
Not saying the 2nd option is always a good idea because it could be very difficult if not impossible to sync up the two containers if they are different depending on your content.
Anyways, in regards to the bicycle wheel, I used that example because I actually had to do a control kind of similiar to that. I wanted to scale the size of the two circles and the *length* of the spokes, but I wanted the stroke thickness of the two circles and the spokes to remain consistent at one pixel.
I did in fact end up using a ViewBox for that, but to keep the lines a consistent stroke thickness, I defined a DependencyProperty of type double that was updated with the inverse scaling ratio as the control was resized and bound it to everything I wanted to keep consistent.
So the original stroke thickness was defined as 1.0, and if the user scaled to 2x the original size for example, the stroke thickness would be updated to 0.5 to keep the lines at 1 pixel thickness. If they scaled to 50%, the stroke thickness would be updated to 2.0.
You really have to play with your particular content to see how it scales in the ViewBox by default. Its sometimes kind of wacky and you have to do wacky stuff to compensate.
|
|
|
|
|
Fully understood. Thanks so much for your time - it's really helped! Uses for dependency properties seem to be a lot more obvious now too... Cheers!
|
|
|
|
|
Is it possible to derive a reusable class from System.Windows.Application? I want to make an "ApplicationEx" class with some extended functionality.
Problem is that App is derived from System.Windows.Application and its a partial class, so if I change App to derive from a class that derives from Application instead of deriving from Application directly, it doesn't jive with the App.g.cs code behind.
What I mean is:
public class ApplicationEx : ApplicationEx
{
}
public partial class App : ApplicationEx // instead of Application
{
}
I don't want to loose app.xaml functionality.
|
|
|
|