|
How can I configure my .net solution/project to allow File IO Permissions? I'm trying to access a .xml file on my hard drive and I get the following error: Request for permission of type 'System.Security.Permissions.FileIOPermissions... failed.
Thanks for your help, Lisa
Lisa
|
|
|
|
|
Either you are running in less than full trust, or you do not have the security permission to access that file.
Is this a web application?
|
|
|
|
|
No this is not a web application. It is a very simple learning winforms Windows Application.
1. On my project / properties / security page I have "This is a full trust application" radio button selected.
2. I created the xml file I am trying to access.
3. I inherited a winforms / C# application, when I try to access files in that solution / project I do not get any errors. I created a new Windows application (solution / project) for my learning and within that project I am not able to access files.
Thanks so very much for your time and help. Lisa
Lisa
|
|
|
|
|
That is weird indeed. Can you post a full stacktrace of the exception, maybe it can be deciphered that way.
|
|
|
|
|
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
Lisa
|
|
|
|
|
This sounds weird.
Can you try the application on another PC? That would tell you if your 'machine' permissions are broken.
What happens when you try load that XML file from a simple console application from your PC?
What is the filename you pass into it?
|
|
|
|
|
The error is caught on the following statement.
Doc.Load("c:\\vs\\Employees.xml");
If I try to run the code from a different .NET Windows Application on my PC it works fine. I did not setup that application, I inherited it from someone. Any new Windows Application that I setup the File IO Permissions does not work.
I really appreciate all you thoughts and suggestions. Thanks, Lisa
Lisa
|
|
|
|
|
It sounds like your security permissions is messed up. You say someone else worked on that PC? Then it is likely the administrator didnt 'clean' the previous users permissions, and thus conflicting.
|
|
|
|
|
|
Is this Vista or Windows XP? Is the XML file in the root of c: ?
|
|
|
|
|
I'm using Windows XP. The file is not in the root of c:, however I have also tried to get the Selected Path from a FolderBrowserDialog and I have the same problem.
When I try this in the Windows Application that I inherited I do not have the problem; that's why I think it is an "environment" problem.
Thanks for your help, Lisa
Lisa
|
|
|
|
|
Hey guys,
is it possible to change the color of individual rows in a DataDridView?
The data will be employees loaded into my application, the idea is to keep the row color of active employees white, make inactive - grey, make temporary - light green & make terminated - Red
any ideas where to start?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: is it possible to change the color of individual rows in a DataDridView?
You could certainly do it via the 'CellFormatting' event by modifying the CellStyle.ForeColor and CellStyle.BackColor to whatever you desired. However, in that event you would need to change all the cells in the row to impact the entire row. There might be a way to do it automatically for the entire row as opposed to doing it cell-by-cell.
|
|
|
|
|
yeah cell by cell wouldn't be the best solution for this particular problem because each row has about 20 cells, and there will be a few 1000 rows at a time...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
I need select from list containing product code and name but show only code in combo textbox.
Tried code below but dropdown list shows only code.
How to display both code AND name in selection list ?
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
ComboBox cm = new ComboBox() { DisplayMember = "DisplayMember", ValueMember = "Code" };
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine", Cb = cm });
prodList.Add(new Product() { Code = "002", Name = "Beer", Cb = cm });
cm.DataSource = prodList;
cm.DataBindings.Add("SelectedValue", prodList, "Code");
Controls.Add(cm);
}
class Product
{
public ComboBox Cb;
public string Code { get; set; }
public string Name { get; set; }
public string DisplayMember
{
get
{
if (Cb.DroppedDown)
return Code + " " + Name;
else
return Code;
}
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|
|
hi
override the ToString() function in the product class and return the formated string with both properties.
regards
|
|
|
|
|
Thank you.
I tried code below but dropdown list shows only code.
How to force it to show both code and name ?
Andrus.
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
ComboBox cm = new ComboBox()
{
ValueMember = "Code"
};
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine", Cb = cm });
prodList.Add(new Product() { Code = "002", Name = "Beer", Cb = cm });
cm.DataSource = prodList;
cm.DataBindings.Add("SelectedValue", prodList, "Code");
Controls.Add(cm);
}
class Product
{
public string Code { get; set; }
public string Name { get; set; }
public override string ToString()
{
return Code + " " + Name;
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|
|
try to add only the class object. do not set databindings. then in the selectedindexchanged event
cast the selecteditem to the class object.
Product product = (Product)myComboBox.Items[myComboBox.SelectedIndex];
|
|
|
|
|
Thank you. I tried the code below but TextBox in combo shows name also.
How to show only code ?
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
MultiComboBox cm = new MultiComboBox() ;
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine" });
prodList.Add(new Product() { Code = "002", Name = "Beer" });
cm.DataSource = prodList;
Controls.Add(cm);
}
class MultiComboBox : ComboBox
{
protected override void OnSelectedIndexChanged(System.EventArgs e)
{
Product product = (Product)Items[SelectedIndex];
SelectedItem = product.Code;
base.OnSelectedIndexChanged(e);
}
}
class Product
{
public string Code { get; set; }
public string Name { get; set; }
public override string ToString()
{
return Code + " " + Name;
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|
|
When the code runs, the value of Cb.Dropped is always false. Stepping through.
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
|
Munna Sarfraz Ahmad,
And the question was?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Thank you for the Copy and Paste directly from the internet.
Dave
|
|
|
|
|
Just a crop-dusting across forums. And they call themselves 'software engineers '.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
What on earth made you think you needed to post that here?
|
|
|
|