This is a migrated thread and some comments may be shown as answers.

Access file info

1 Answer 68 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 04 Sep 2013, 08:54 AM
There is a folder for my project that has files uploaded in it. From C# I am trying to access the required file using the name and hence its informations using code.
FileInfo myfile=new FileInfo(filename);
The var filename is a string with the name of one of the uploaded file but running the app gives me Access denied error. Any special permissions is there to access the directory with the file.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Sep 2013, 10:39 AM
Hi Joseph,

You cannot access files you've placed in the project using the FileInfo object. Instead you create a Uri to access it.

Its not clear from your question which project you've place the file in. If you have placed it in the Silverlight project then it ought to end up as content in the Xap where you can use StreamResourceInfo to access it as follows.

C#:

StreamResourceInfo fileContentInfo = Application.GetResourceStream(new Uri(filename, UriKind.Relative));

Also now the file content could be accessed as follows.

C#:
Stream fileStream = fileContentInfo.Stream;

Thanks,
Princy.

Tags
Upload
Asked by
Joseph
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or