May be some body have FLA file which download file to folder (without dialog of save file).
Just Click to - DOWNLOAD -> file save to folder /update on swf located. (without any confirmation of filename or filder location)
var fileName:String = "upgrade.zip";
var request:URLRequest = new URLRequest();
request.url = DOWNLOAD_URL;
var params:URLVariables = new URLVariables();
fr.download(request,fileName);
This change filename in dialog only, but dialog must to be auto-agreed.
And more one. When I try to make AS3 script, for download via URLRequest, this work only in Flash editor. FLA file (when I comp[ile to SWF -> not work).
Related
I've added my file into resources with right click -> existing item.
Now I want to copy the added file into another directory like this:
File.Copy(#"I don't know", #"C:\Users\user-1\Desktop\", true);
I don't know what I have to write in #"I don't know" part to addressing the added resource file.
If myDir is the directory of your project, the resources' file has path myDir\Properties\Resources.resx.
Now, when you execute a program from Visual Studio in Debug mode, the folder is myDir\Bin\Debug.
You have to go up 2 folders and enter the Properties folder:
var resourcesFileName = "Resources.resx";
var currentDirectory = Directory.GetCurrentDirectory();
var actualResourceFilePath = Path.Combine(
currentDirectory, "..", "..", "Properties", resourcesFileName);
var desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var newFilePath = Path.Combine(desktop, resourcesFileName);
File.Copy(actualResourceFilePath, newFilePath, true);
I suggest you to not use the path separator in the hard-coded way (#"dir1\dir2...").
Use Path.Combine instead.
Hi I have a wpf application that plays sounds on events such as button click. And the current code I have now plays the sound file, but Ive realized that it has to be in another folder which for example if the user deletes, makes the application pretty much not useable.
I was wondering, How could I get a .wav file without creating a whole new folder in the application Release directory.
Any ideas?
Thanks.
If the .wav files is added to your project at the root then marked as content (Right Click on the .wav file and click properties. Then change the build action to content) then it will be copied directly to the root output folder
You can the reference the wav file in code or XAML as a relative path (simple "Myfile.wav")
I believe this is what you are asking for?
How about putting the .wav-file as en embedded resource in the dll?
Just add the file to the project, right-click on the file and set Build Action to Embedded Resource.
Then you can load the .wav file as a stream and save it to disc like this:
private void WriteEmbeddedResourceToFile(string writePath, string assemblyName)
{
Assembly asm = Assembly.GetExecutingAssembly();
Stream s = asm.GetManifestResourceStream(assemblyName);
if (s != null)
{
var file = new byte[s.Length];
s.Read(file, 0, (int)s.Length);
File.WriteAllBytes(writePath, file);
s.Close();
}
}
The string assemblyName must be set like this: namespace.(if you put the file in a folder, insert folder subpath here).filename.wav
Alternatively, you can drop saving it to disc, and just use the stream directly:
private byte[] GetEmbeddedResource(string assemblyName)
{
Assembly asm = Assembly.GetExecutingAssembly();
Stream s = asm.GetManifestResourceStream(assemblyName);
if (s != null)
{
var file = new byte[s.Length];
s.Read(file, 0, (int)s.Length);
s.Close();
return file;
}
}
Then, when you want to load the file, GetEmbeddedResource will return the byte array.
In my WPF app, I am creating a FlowDocument by building its XAML markup as a string, and then using XamlReader.Parse to turn the string into a FlowDocument object, which I then save to an XPS document file. It works.
I needed to include an image in my document, and so to achieve this, I create and save the image as a temporary file in the temp directory, and then reference it with an absolute path in my FlowDocument's XAML. This works too - during the XPS document creation process, the image actually gets embedded into the XPS document, which is great.
But the problem is, my app retains a file lock on this image until the app quits.
I am cleaning up all resources. There is NO file lock on my generated XPS file - just the image file. If I comment out the part of my code which creates the XPS file, then the image file does not get locked.
My code (I'm on .NET 4 CP):
var xamlBuilder = new StringBuilder();
// many lines of code like this
xamlBuilder.Append(...);
// create and save image file
// THE IMAGE AT THE PATH imageFilePath IS GETTING LOCKED
// AFTER CREATING THE XPS FILE
var fileName = string.Concat(Guid.NewGuid().ToString(), ".png");
var imageFilePath = string.Format("{0}{1}", Path.GetTempPath(), fileName);
using (var stream = new FileStream(imageFilePath, FileMode.Create)) {
var encoder = new PngBitmapEncoder();
using (var ms = new MemoryStream(myBinaryImageData)) {
encoder.Frames.Add(BitmapFrame.Create(ms));
encoder.Save(stream);
}
stream.Close();
}
// add the image to the document by absolute path
xamlBuilder.AppendFormat("<Paragraph><Image Source=\"{0}\" ...", imageFilePath);
// more lines like this
xamlBuilder.Append(...);
// create a FlowDocument from the built string
var document = (FlowDocument) XamlReader.Parse(xamlBuilder.ToString());
// set document settings
document.PageWidth = ...;
...
// save to XPS file
// THE XPS FILE IS NOT LOCKED. IF I LEAVE OUT THIS CODE
// AND DO NOT CREATE THE XPS FILE, THEN THE IMAGE IS NOT LOCKED AT ALL
using (var xpsDocument = new XpsDocument(filePath, FileAccess.ReadWrite)) {
var documentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
documentWriter.Write(((IDocumentPaginatorSource) document).DocumentPaginator);
xpsDocument.Close();
}
(Actually, the fact that's it's a dynamically generated image in the temp directory is irrelevant - this issue occurs if I hard code in the path of any image file on my machine - it will get locked.)
One would think that there is a bug in the XPS creation code that causes the file lock.
Is there something else I can try? Or a way to remove the file lock via code?
You could change your xaml like this instead:
<Image>
<Image.Source>
<BitmapImage CacheOption="None" UriSource="your path" />
</Image.Source>
</Image>
to be able to play with the CacheOption parameter, to specify how the Xaml Builder should load the image file, as the default value seems to be keeping a lock on it (waiting for the GC to do its work it seems).
Here is some related question here on SO: How do you make sure WPF releases large BitmapSource from Memory?
I want to save (upload) a file in silverlight into the silverlight application folder.
I get the URI of the application
string str3 = App.Current.Host.Source.AbsoluteUri + "/Recording/";
but i don't know how to save file.
I use this code.....
string extension = "wav";
// Create an instance of the open file dialog box.
OpenFileDialog openFileDialog1 = new OpenFileDialog();
// Set filter options and filter index.
openFileDialog1.Filter = String.Format("{1} files (*.{0})|*.{0}|WAV FILES (*.*)|*.*", extension, "Audio");
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = false;
// Call the ShowDialog method to show the dialog box.
bool? userClickedOK = openFileDialog1.ShowDialog();
// Process input if the user clicked OK.
if (userClickedOK == true)
{
string str = App.Current.Host.Source.AbsoluteUri + "/Recording/";
openFileDialog1.File.CopyTo(str);
}
That won't work by itself (I assume your application is hosted on a web server), you need an uploader that will send the content to the server, and a server side handler that will receive and store the file.
Take you pick from one of those Silverlight uploaders:
Silverlight File Uploader
Silverlight File Upload
Silverlight Multi File Uploader
Personally I went with the first one, but I believe they're all quite good.
So I am trying to create an image gallery. My AIR application accepts files that are dragged and dropped onto a TileList component. I am using the images as icons but the problem is that they take a long time to load so i want to compress the file data first (I have that part done) The problem is that I can't figure out how to open the file and put the data into a BitmapData object.
Any ideas?
var req:URLRequest = new URLRequest(value.file.url);
var ldr:Loader = new Loader();
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
ldr.load(req);
.
.
.
private function completeHandler(event:Event):void {
var ldr:Loader = Loader(event.target.loader);
var b:Bitmap = Bitmap(ldr.content);
}