I get a "Operation not permitted on IsolatedStorageFileStream" error when i try to run this code:
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.FileExists("Lokacije.abc"))
isf.CreateFile("Lokacije.abc");
using (var stream = new IsolatedStorageFileStream("Lokacije.abc", FileMode.Append, FileAccess.ReadWrite, isf))
{
using (var sw = new StreamWriter(stream))
{
sw.Write(string.Format("GC-X({0})-Y({1})|", x, y));
}
}
}
Does anyone have an idea what it could be?
I am not using the storage in any other place in my application so its impossible that it is already in use.
Check that you don't somehow have two threads accessing IsolatedStorage at the same time (ie. in VS Debug.View.Threads and verify that at the time of the exception you don't have multiple paths through the same IsoStore code).
For more refer these:
http://social.msdn.microsoft.com/Forums/wpapps/en-US/a1bb0b15-6bc0-4c63-ac94-ec1e63242cf1/operation-not-permitted-on-isolatedstoragefilestream?forum=wpdevelop
Operation not permitted on IsolatedStorageFileStream error
Hope it helps!
Related
I have an Adobe Air Application that would open an csv file on Mac. I am getting an error which I am not getting with the same app for Windows, so I am thinking something about file locations, etc is amiss. Here is the code:
var file: File = File.applicationStorageDirectory;
file = file.resolvePath("A&P plans");
file.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
function filesSelected(event: FileListEvent): void {
//trace(event.files.length);
fileList = new Array();
fileNames = new Array();
for (var i: uint = 0; i < event.files.length; i++) {
fileList.push(event.files[i].nativePath);
trace("name of file loaded is ", event.files[i].name, "where :", event.files[i].nativePath);
}
}
var urlRequest: URLRequest = new URLRequest(fileList[0]);
function openCSVFile():void{
csv = new CSV(urlRequest);
csv.addEventListener(Event.COMPLETE,onComplete);
csv.addEventListener(IOErrorEvent.IO_ERROR, onErrorOpening);
function onComplete(event:Event):void{
trace("file open successful");
}
function onErrorOpening(event:IOErrorEvent):void{
trace ("error opening file");
}
}
The URLRequest trace shows the location where it should be, so the app knows where to look, and it does find the file. Here is the result of the trace :/Applications/myApp.app/Contents/Resources/A&P plans/majors/NationalLeague.csv. Yet, instead of the completeEvent showing the trace, the errorEvent is inovked. Any ideas where to look for the issue? The file does not have any weird characters in its name or anything. Tracing the error shows the following: Error #2032: Stream Error. Thanks
Quite possibly the ampersand and the space in 'A&P plans' might be troublesome.
Try removing/changing those.
I have a script I've been running successfully for a couple weeks now but this week it has started failing with the error shown above. I have not changed anything in the script, so I don't know why this is suddenly happening every time I run it.
Was there a release or server side issue that could have caused this fallout? Like I said this code and any code that fed into it have not been changed since it was working fine and the error is providing me with no other information. This is also not the only function experiencing the problem, every time I try to use setNumberFormats it is failing.
Sorry that this is broad, but the issue I'm experiencing is broad.
function pasteObjectsToSheet(objects, range, locations) {
const values = []
const formats = []
for (var i = 0; i < objects.length; i++) {
var object = objects[i]
var value = new Array(locations.length)
var format = new Array(locations.length)
for (var key in object) {
var index = locations.indexOf(key)
if (index > -1) {
value[index] = object[key].value
format[index] = object[key].format
}
}
values.push(value)
formats.push(format)
}
range.setValues(values)
range.setNumberFormats(formats)
}
The main issue of the original poster in this question was a typo. Instead of writing format in format[index] = object[key].format he wrote formt.
I am trying to experiment with downloading files on a regular basis with background tasks for windows store applications, and am having trouble.
I followed the sample at https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh977055.aspx, and even downloaded/ran it and everything worked perfectly (including being able to step into the timer background task).
So with that I created my own background task in a brand new Windows namespace
Win8BackgroundTest
{
public class TestBackgroundTask
{
public async void Run(IBackgroundTaskInstance taskInstance)
{
var deferral = taskInstance.GetDeferral();
var uri = new Uri("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_h264.mov");
var folder = ApplicationData.Current.LocalFolder;
var downloadFile = await folder.CreateFileAsync(uri.Segments.Last(), CreationCollisionOption.GenerateUniqueName);
var dataFile = await folder.CreateFileAsync("downloadData", CreationCollisionOption.GenerateUniqueName);
var downloader = new BackgroundDownloader();
var operation = downloader.CreateDownload(uri, downloadFile);
await FileIO.WriteTextAsync(dataFile, "Success at " + DateTime.Now);
deferral.Complete();
}
public static async void RegisterTask()
{
const string taskName = "TestBackgroundTask";
try
{
var status = await BackgroundExecutionManager.RequestAccessAsync();
if (status == BackgroundAccessStatus.Denied)
{
return;
}
}
catch
{
// already accepted
}
var tasks = BackgroundTaskRegistration.AllTasks
.Where(x => x.Value.Name == taskName)
.ToArray();
if (tasks.Any())
{
return;
}
var builder = new BackgroundTaskBuilder
{
Name = taskName,
TaskEntryPoint = "Win8BackgroundTest.TestBackgroundTask",
};
builder.SetTrigger(new TimeTrigger(60, false));
var registeredTask = builder.Register();
}
}
}
I set up the application's manifest with a Background Tasks declaration, checking the Timer properties checkbox, and set the EntryPoint to Win8BackgroundTest.TestBackgroundTask.
I then added the following at the end of my App.xaml.cs's OnLaunched() method:
TestBackgroundTask.RegisterTask();
Stepping through seems to have task registration work successfully with no exceptions. I then go back to visual studio, added a breakpoint to the first line in my task's Run() method, I then go to the debug locations toolbar, click the down arrow and select TestBackgroundTask. A few seconds later visual studio exits (as does my app).
Does anyone see what I am doing wrong that is causing background tasks to fail?
So after much frustration and a lot of trial and error the issue was a combination of both of the comments.
So first of all, it appears like you cannot have a background task in the same project as the rest of your windows store application. It must be in it's own windows runtime component project.
Finally, there are times where it just doesn't work and for whatever reason deleting the bin and obj folders fix it.
We loaded video as bytes array, created InMemoryRandomAccessStream over this array and tried to MediaElement.SetSource. In UI we have message on MediaElement - Invalid Source. We tried to save this stream to file and read new stream from this file - works perfectly. Both stream are the identical (we check it using SequenceEqual).
What is the problem?
Part of our code:
var stream = await LoadStream();
mediaElement.SetSource(stream , #"video/mp4");
...
public async Task<IRandomAccessStream> LoadStream()
{
...
var writeStream = part.ParentFile.AccessStream.AsStreamForWrite();
foreach (var filePart in part.ParentFile.Parts)
{
writeStream.Write(filePart.Bytes, 0, filePart.Bytes.Length);
}
writeStream.Seek(0, SeekOrigin.Begin);
return part.ParentFile.AccessStream;
}
P.S - the mime-type is correct for sure
Thanks!
I try to use FileStream (using namespace System.IO) but I get an exception :
Attempt to access the method failed
Here is the code :
FileStream fs = new FileStream("file.txt", FileMode.Create);
I searched on microsoft.com and I found that this error is because I use a bad library reference.
But in my project, I compile with mscorlib.dll from folder : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0
I need some help, please.
You will need to use IsolatedStorage, for example:
Place at the top of your file:
using System.IO.IsolatedStorage;
Then in your method do this:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var istream = new IsolatedStorageFileStream("File.txt", FileMode.OpenOrCreate, store))
{
using (var sw = new StreamWriter(istream))
{
sw.Write("Some Stuff");
}
}
}
A great example and explanation of this and other operations can be found here: http://msdn.microsoft.com/en-us/library/cc265154(v=VS.95).aspx#Y300
You can look through your IsolatedStorage by using the Windows Phone 7 IsolatedStorageExplorer
A good place to start for documentation: http://msdn.microsoft.com/library/ff626516(v=VS.92).aspx
Also here: http://create.msdn.com/en-us/education/documentation
On WindowsPhone you must use IsolatedStorage - see this tutorial for example - http://3water.wordpress.com/2010/08/07/isolated-storage-on-wp7-ii/
Read:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var readStream = new IsolatedStorageFileStream(fileName, FileMode.Open, store))
using (var reader = new StreamReader(readStream))
{
return reader.ReadToEnd();
}
Write:
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
using (var writeStream = new IsolatedStorageFileStream(fileName, FileMode.Create, store))
using (var writer = new StreamWriter(writeStream))
{
writer.Write(content);
}