|
If I get this question answered, a lot of gaps in my understanding of Websites are going to be filled in, so hopefully someone will give me the answer.
I have a WCF-based Web service for my Silverlight Website application and the Web service DLL is located in /bin off of the root of the Website. It has many services correctly accessing a SQL Server database and sending email to the client, so I know that it is set up correctly.
Now, I have a bunch of JPEG files in /bin/ClientBin/SplashScreenPhotos. I would like to add another service that returns an ObservableCollection<string> of JPEG file names (just the file names, not the whole path) to my Silverlight application. Once the application has that, it knows how to display those JPEG files, because it's doing it now with a list of file names hard-coded in the Silverlight application (hard-coding things is bad).
My idea is to create a service that would look like this to populate the ObservableCollection :
[OperationContract]
public bool GetList(out ObservableCollection<string> list)
{
list = new ObservableCollection<string>();
string folder = ???;
string[] files = Directory.GetFiles(folder, "*.jpg");
foreach (string path in files)
{
string fileOnly = System.IO.Path.GetFileName(path);
list.Add(fileOnly);
}
return true;
}
My question thus is, what do I substitute for the ??? This is basically a question of how the service navigates through the Website file system. I've been fooling with this for hours without getting anywhere. Using paths like /bin/ClientBin/SplashScreenPhotos does not work. I'm thinking that I'm probably off-base in using the .NET Directory class to begin with, but I don't know what I should be using.
[WORKAROUND added 2010-06-07]: I solved my problem through a fairly simple workaround. Instead of my service accessing my Website's file system directly (for all I know, something that is impossible), I used the FtpWebRequest class to do the job for me. The WebRequest.Method was WebRequestMethods.Ftp.ListDirectory , which returns a WebResponse object, from which you can create a StreamReader initialized with WebResponse.GetResponseStream() . I implemented the whole thing needed by the Web service through the following function, which the service calls:
ObservableCollection<string> GetFileNamesFromFtpDirectory(string remotePath)
{
var result = new ObservableCollection<string>();
Uri uri = new Uri(remotePath);
WebRequest ftp = FtpWebRequest.Create(uri) as FtpWebRequest;
ftp.Credentials = new NetworkCredential("xxxx", "yyyy");
ftp.Method = WebRequestMethods.Ftp.ListDirectory;
WebResponse response = null;
try
{
response = ftp.GetResponse();
}
catch (Exception e)
{
string error = e.Message;
return null;
}
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string line = reader.ReadLine();
while (line != null)
{
result.Add(line);
line = reader.ReadLine();
}
}
return result;
}
"xxxx" and "yyyy" are top secret strings that provide my Website credentials. The remotePath input to the function is something like this:
"ftp://www.website.com/ClientBin/SplashScreenPhotos"
modified on Monday, June 7, 2010 4:29 PM
|
|
|
|
|
Well, it doesn't look as if anyone is interested in answering this question, or, incredibly, that no one monitoring this forum even knows what the answer is. Actually, it seems as if this is about as basic a Website question as a person could possibly ask, so maybe this is just the wrong forum: its answer may be so obvious to any Website developer worth his salt that he would have contempt for anyone who would even ask such a question.
On the other hand, I've noticed very light activity on this Silverlight forum, indicating that there just aren't that many people out there yet doing serious work on this technology. So the only thing I can personally recommend to solve this problem is a workaround.
|
|
|
|
|
I have 3 projects in my app, plus main project used for navigation.
I use the navigation service to move around but there is that incessant clicking sound.
Can anyone offer me insight how in my code I can remove the clicking sound? Examples would be appreciated. Thanks in advance.
|
|
|
|
|
Good day,
I wan't to ask something that is obvious to do in VS 2005 and VS 2008 (WPF), but for some reason, I am struggling my but of in VS 2010 (WPF).
I want to dynamically load items into a ListBox, but for some reason it does not want to show up in the ListBox, they are there (I perform a count on the ListBox, and it shows the expected number).
Here is how I do it:
First of, I add an item like this: this.lstItems.Items.Add(OtherStackPanel(temp));, where OtherStackPanel is a function that returns a populated stackpanel, with the following items:
1 x Label, 1 x TextBox, 1 x ComboBox, 3 x Seperator, 1 x Slider, which look as follows
__________________________________________________________________________
| | | | | | | |
|ComboBox | Seperator | Label | Seperator | TextBox | Seperator | Slider |
|__________|___________|_______|___________|_________|___________|________|
This would then be added to the ListBox, all the items in the StackPanel are set to be visible, and they have a parent since they are added to the StackPanel.
After I have added the StackPanel, I call the LayoutUpdated event of the ListBox, to make sure that they are contained in the ListBox, but I also add two addisional items from within this eventhandler, as follows:
private void listBox1_LayoutUpdated(object sender, EventArgs e)
{
if (sender != null)
{
ListBoxItem l = new ListBoxItem();
l.Content = "S";
ListBoxItem n = new ListBoxItem();
n.Content = "A";
((ListBox)sender).Items.Add(l);
this.lstItems.Items.Add(n);
MessageBox.Show(((ListBox)sender).Name);
MessageBox.Show(Convert.ToString(((ListBox)sender).Items.Count));
}
}
((ListBox)sender).Name returns ListBox, which is correct, since the item passed to this event is that listbox, and ((ListBox)sender).Items.Count returns 3, which is correct, since I have added the StackPanel, "S" and "A", but for some odd reason, I cannot see the items in the ListBox.
I have tried this.lstList.Items.Insert(0, "S"), but to no avail!
If you could provide a possible solution, I would really appreciate it (I don't know why it is so much different than VS 2008 WPF).
I am using Windows 7 Ulitmate.
Kind Regards,
Rossouw
|
|
|
|
|
I have embedded in my ASP.NET web page a Silverlight control that uses the Silverlight 4 audio recorder to allow users to record audio remotely through their browser. For now I am capturing the audio in a stream in memory in the Silverlight control on the client side and then, when the recording is complete, my Silverlight control calls a web service hosted by my server to uploading the complete audio 'file'.
This works okay with reasonably small audio recordings, but I need to allow my users to record fairly long audio recordings. The best solution I can think of for this is to have my Silverlight app do some type of streaming upload to the server as the audio is being recorded, so that the Silverlight app doesn't have to save the entire recording in memory and wait for the recording to complete before transmitting it to the server.
Can anyone tell me if this is possible and, if so, what I would need to do to get started streaming the audio as it is being recording in my Silverlight app to the server?
Any help would be greatly appreciated!!
|
|
|
|
|
Silverlight supports sockets. You could store the file in the Isolated storage and upload it via sockets on another thread.
|
|
|
|
|
Hi,
I need to build an image editor that should have all the functionalities of photoshop. The images should be loaded in a repeater or a listview control showing thumbnails. I should be able to drag the thumbnail on to a canvas and be able to edit the image, add layers etc...similar to photoshop and finally print it as a PDF. So far all my efforts to do this have failed. Kindly help me.
I have started developing the application. I have sucessfully loaded a Repeater Control with images...sort of like an image gallery. Now i want to drag those images into a canvas like that of photoshop and be able to add layers and other effects. I am unable to do that. Is there a way to drag items from a Repeater control and is there a way to call Photoshop in a .NET Application??
|
|
|
|
|
You have got the wrong forum.
This is the Silverlight forum.
My signature "sucks" today
|
|
|
|
|
ikbegins wrote: I need to build an image editor that should have all the functionalities of photoshop.
Then you're going to build an app with about ten million lines of code in it? Not meaning to sound sarcastic, but you and what army?
|
|
|
|
|
I got the impression he does not want to reverse engineer PS but use it from a silverlight web application. Drag the image onto a control that opens PS with the image loaded seems a doable solution. I think the OP is possibly struggling with english.
OTOH If he does want to build PS
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hey Microft...you got that 100% right. Thats exactly what i wanted to do. Create a Silverlight web application having an image gallery. I should be able to drag images from that gallery and drop it in a canvas and be able to edit the image there. Is there a way to call the photoshop interface somehow and edit the image? I think my english is fine. I am sorry i wasnt clear before. Hey thats the way clients give their requirements! lol.
So is there a way to achieve this?
Regards,
Imran
|
|
|
|
|
ikbegins wrote: Is there a way to call the photoshop interface somehow
Don't know, never used it. I would go pester Adobe, I'm dammed sure they have a support forum and "Photoshop API" might get you something.
Just don't let the client get you to try and embed PS in your web page
I would look at opening PS with the file name, does double clicking on a file open PS if it set as the default editor.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hi,
I don't understand how i can use viewbox control in Silverlight 3.
I may use Silverlight Toolkit (for SL 3) or Silverlight 3 Controls implements native Viewbox?
When i use this :
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
<controls:viewbox>
It doesn't work :
The tag 'Viewbox' does not exist in XML namespace 'clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit'.
Somebody can help me ?
(Note: I use Visual Studio 2010 as the IDE)
Thanks
|
|
|
|
|
To use the viewbox, you need to use xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit" .
This is a part of the Silverlight toolkit available here.
My signature "sucks" today
|
|
|
|
|
|
Have you added a reference to the toolkit dll in your project?
My signature "sucks" today
|
|
|
|
|
|
Just uninstall silverlight toolkit and
install it from following path.
I think it has been overridden by older version or
when you installed vs 2010 it may conflicted with the
existing silverlight version.
And close vs 2010 b4 you install silverlight toolkit.
http://silverlight.codeplex.com/[^]
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Viewbox is supported in Silverlight 4 so you cant use it directly in Silverlight 3. If you want to use it in version 3, then you will need to use the Silverlight Toolkit.
-Mamta
|
|
|
|
|
I'm using the Silverlight 4 Tookit Expander all over the place. They are all contained within a ScrollViewer. Sometimes when I expand one of the Expander elements, the Expander.Header winds up above the top of the ScrollViewer and hence is not visible and so you can't see the title of the content that has been expanded. What I would like to do is center the Expander header vertically within the ScrollViewer viewport when I expand the Expander. To do this I have to set the ScrollViewer.VerticalOffset to the right value that will center the Expander in the ScrollViewer viewport.
So I think I understand the problem that needs to be solved. But I haven't found a solution. Hopefully it's simple and I'm just overlooking something.
The only ScrollViewer properties I've found that might be relevant to this problem are the following: ViewportHeight, VerticalOffset, ExtentHeight, and ActualHeight. I also have the mouse cursor Point relative to the Expander when the Expanded event takes place. But even with all this information, I don't seem to have the right information to compute what the VerticalOffset of the ScrollViewer should be.
SOLUTION: Chalk up my inability to solve this to plain and simple User Brain Damage. The solution was SMOP: a Small Matter Of Programming.
Most of the properties I identified above are not needed, only the following: VerticalOffset, ViewportHeight, and the Y coordinate of the mouse cursor position. Oh, yes! You have to perform the computation in the right event: Expander.SizeChanged, not Expander.Expanded. Only perform the offset if Expander.IsExpanded is true.
So the code in my SizeChanged event looks like this:
private void expander_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expander expander = sender as Expander;
if (expander != null && expander.IsExpanded)
{
double viewportHeight = scrollViewer.ViewportHeight;
double verticalOffset = scrollViewer.VerticalOffset;
double mouseVerticalOffset = MouseCursorPosition.Y;
double newVerticalOffset =
verticalOffset - viewportHeight / 2 + mouseVerticalOffset;
scrollViewer.ScrollToVerticalOffset(newVerticalOffset);
}
}
FYI, MouseCursorPosition is one of my properties, set in my ScrollViewer's MouseMove event. Seems kind of expensive, but it doesn't seem to interfere with the UI response and I don't know of any other way to get the mouse cursor position.
|
|
|
|
|
fjparisIII wrote: Only perform the offset if Expander.IsExpanded is true.
Actually I like it better if you center the Expander whether or not it is expanded. Now all I have to do is animate the centering so that it doesn't jump to the middle so violently.
|
|
|
|
|
fjparisIII wrote: Now all I have to do is animate the centering so that it doesn't jump to the middle so violently.
Impossible, at least by using a Storyboard. The only thing you can animate with a Storyboard is a Dependency Property and the ScrollViewer's VerticalOffset property is read-only. Major bummer. Why did they do that???
Googled around a bit and I found two workarounds. First you can write a ScrollViewer extension adding a dependency property implemented using ScrollViewer.ScrollToVerticalOffset(). Second, you can bite the bullet and do it the old-fashioned way: use a DispatcherTimer, which itself would call ScrollToVerticalOffset().
|
|
|
|
|
Did you try setting the VerticalContentAlignment and the VerticalAlignment to stretch for the expander and for the scrollviewer?
My signature "sucks" today
|
|
|
|
|
Abhinav S wrote: Did you try setting the VerticalContentAlignment and the VerticalAlignment to stretch for the expander and for the scrollviewer?
No. What's that supposed to accomplish? The solution I posted works perfectly fine. Besides, I've moved beyond that now and am working on animating the scroll to the center of the viewport, using a DispatcherTimer . I've got it working beautifully, but I had to set the timer interval to 1/120 of a second to get a smooth scroll. 1/60 of a second for some reason produces a jerky scroll.
I've been experimenting with the duration. So far I like a duration of 0.2 seconds, producing 24 intervals. Each interval scrolls 15 vertical pixels within a viewport of 860 pixels (i.e. scrolling a little less than 430 pixels when the Expander is at the top of the viewport). Eminently smooth.
Anyhow, this animation stuff is far more interesting than centering the Expander , which as far as I'm concerned I solved to my satisfaction hours ago.
I'll show my animation code when I've sufficiently polished it. I've created a class to perform the animation, because I have about 100 Expander elements in 12 different classes, so I need to be clean about this.
|
|
|
|
|