473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Protection Level Problem with DirectoryInfo


This following innocuous code:
System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo();
System.IO.FileInfo[] ppp = fff.GetFiles( Request.MapPath(".") );
for( int ccc=0 ; ccc < ppp.Length ; ccc++ )
{
System.Web.HttpResponse.Response.Write(
"<a href=\"" + Request.MapPath(".") + "/" +
HttpUtility.HtmlEncode(ppp[ccc].Name) + "\">link</a>" );
}

Leads to this error:

System.IO.DirectoryInfo.DirectoryInfo() is inaccessible due to its
protection level

How can I get around that? I want to simply enumerate files in a
directory and put them in a DataList of <a> tags for UI clicking. I
have stripped out the DataList-binding code in the example and reduced
it to Response.Write statements.
Thanks.
Nov 19 '05 #1
3 2361
if you read the documentation, you will see that DirectoryInfo does not have
an empty constructor and that GetFiles wants a file pattern match, not a
directory name. try:

System.IO.DirectoryInfo fff = new
System.IO.DirectoryInfo(Request.MapPath(".") );
System.IO.FileInfo[] ppp = fff.GetFiles();

-- bruce (sqlwork.com)

"xenophon" <xe******@online.nospam> wrote in message
news:ni********************************@4ax.com...

This following innocuous code:
System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo();
System.IO.FileInfo[] ppp = fff.GetFiles( Request.MapPath(".") );
for( int ccc=0 ; ccc < ppp.Length ; ccc++ )
{
System.Web.HttpResponse.Response.Write(
"<a href=\"" + Request.MapPath(".") + "/" +
HttpUtility.HtmlEncode(ppp[ccc].Name) + "\">link</a>" );
}

Leads to this error:

System.IO.DirectoryInfo.DirectoryInfo() is inaccessible due to its
protection level

How can I get around that? I want to simply enumerate files in a
directory and put them in a DataList of <a> tags for UI clicking. I
have stripped out the DataList-binding code in the example and reduced
it to Response.Write statements.
Thanks.

Nov 19 '05 #2
Hi xenophon,

As Bruce has mentioned, the problem you ecountered is a compile time error.
The DirectoryInfo class has no default constructor and we need to provide
the directory's path in the DirectoryInfo class's constructor rather than
in GetFiles function.
The GetFiles function's string parameter is used to represent file name
pattern. For example:

private void Page_Load(object sender, System.EventArgs e)
{
System.IO.DirectoryInfo fff = new DirectoryInfo(Server.MapPath("."));
System.IO.FileInfo[] ppp = fff.GetFiles("*.aspx");

DataGrid1.DataSource = ppp;
DataGrid1.DataBind();
}

If there're any other questions on this, please feel free to post here.
Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Bruce Barker" <br******************@safeco.com>
| References: <ni********************************@4ax.com>
| Subject: Re: Protection Level Problem with DirectoryInfo
| Date: Thu, 3 Nov 2005 09:22:51 -0800
| Lines: 47
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| Message-ID: <#A**************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: rdcsd1.safeco.com 12.144.134.2
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:135863
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| if you read the documentation, you will see that DirectoryInfo does not
have
| an empty constructor and that GetFiles wants a file pattern match, not a
| directory name. try:
|
| System.IO.DirectoryInfo fff = new
| System.IO.DirectoryInfo(Request.MapPath(".") );
| System.IO.FileInfo[] ppp = fff.GetFiles();
|
| -- bruce (sqlwork.com)
|
|
|
| "xenophon" <xe******@online.nospam> wrote in message
| news:ni********************************@4ax.com...
| >
| > This following innocuous code:
| >
| >
| > System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo();
| > System.IO.FileInfo[] ppp = fff.GetFiles( Request.MapPath(".") );
| > for( int ccc=0 ; ccc < ppp.Length ; ccc++ )
| > {
| > System.Web.HttpResponse.Response.Write(
| > "<a href=\"" + Request.MapPath(".") + "/" +
| > HttpUtility.HtmlEncode(ppp[ccc].Name) + "\">link</a>" );
| > }
| >
| >
| >
| >
| >
| > Leads to this error:
| >
| > System.IO.DirectoryInfo.DirectoryInfo() is inaccessible due to its
| > protection level
| >
| > How can I get around that? I want to simply enumerate files in a
| > directory and put them in a DataList of <a> tags for UI clicking. I
| > have stripped out the DataList-binding code in the example and reduced
| > it to Response.Write statements.
| >
| >
| > Thanks.
| >
| >
|
|
|

Nov 19 '05 #3
Hi xenophon,

Does the things in our former messages help you resolve the problem? If
there're anything else we can help, please feel free to post here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 64214682
| References: <ni********************************@4ax.com>
<#A**************@tk2msftngp13.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online.microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 04 Nov 2005 03:25:52 GMT
| Subject: Re: Protection Level Problem with DirectoryInfo
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| Message-ID: <6c**************@TK2MSFTNGXA01.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Lines: 77
| Path: TK2MSFTNGXA01.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:136031
| NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122
|
| Hi xenophon,
|
| As Bruce has mentioned, the problem you ecountered is a compile time
error.
| The DirectoryInfo class has no default constructor and we need to provide
| the directory's path in the DirectoryInfo class's constructor rather than
| in GetFiles function.
| The GetFiles function's string parameter is used to represent file name
| pattern. For example:
|
| private void Page_Load(object sender, System.EventArgs e)
| {
| System.IO.DirectoryInfo fff = new DirectoryInfo(Server.MapPath("."));
| System.IO.FileInfo[] ppp = fff.GetFiles("*.aspx");
|
| DataGrid1.DataSource = ppp;
| DataGrid1.DataBind();
| }
|
| If there're any other questions on this, please feel free to post here.
| Thanks,
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
| --------------------
| | From: "Bruce Barker" <br******************@safeco.com>
| | References: <ni********************************@4ax.com>
| | Subject: Re: Protection Level Problem with DirectoryInfo
| | Date: Thu, 3 Nov 2005 09:22:51 -0800
| | Lines: 47
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| | X-RFC2646: Format=Flowed; Original
| | Message-ID: <#A**************@tk2msftngp13.phx.gbl>
| | Newsgroups: microsoft.public.dotnet.framework.aspnet
| | NNTP-Posting-Host: rdcsd1.safeco.com 12.144.134.2
| | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msft ngp13.phx.gbl
| | Xref: TK2MSFTNGXA01.phx.gbl
| microsoft.public.dotnet.framework.aspnet:135863
| | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
| |
| | if you read the documentation, you will see that DirectoryInfo does not
| have
| | an empty constructor and that GetFiles wants a file pattern match, not
a
| | directory name. try:
| |
| | System.IO.DirectoryInfo fff = new
| | System.IO.DirectoryInfo(Request.MapPath(".") );
| | System.IO.FileInfo[] ppp = fff.GetFiles();
| |
| | -- bruce (sqlwork.com)
| |
| |
| |
| | "xenophon" <xe******@online.nospam> wrote in message
| | news:ni********************************@4ax.com...
| | >
| | > This following innocuous code:
| | >
| | >
| | > System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo();
| | > System.IO.FileInfo[] ppp = fff.GetFiles( Request.MapPath(".") );
| | > for( int ccc=0 ; ccc < ppp.Length ; ccc++ )
| | > {
| | > System.Web.HttpResponse.Response.Write(
| | > "<a href=\"" + Request.MapPath(".") + "/" +
| | > HttpUtility.HtmlEncode(ppp[ccc].Name) + "\">link</a>" );
| | > }
| | >
| | >
| | >
| | >
| | >
| | > Leads to this error:
| | >
| | > System.IO.DirectoryInfo.DirectoryInfo() is inaccessible due to its
| | > protection level
| | >
| | > How can I get around that? I want to simply enumerate files in a
| | > directory and put them in a DataList of <a> tags for UI clicking. I
| | > have stripped out the DataList-binding code in the example and reduced
| | > it to Response.Write statements.
| | >
| | >
| | > Thanks.
| | >
| | >
| |
| |
| |
|
|

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

75
by: Massimo | last post by:
I'm planning to develop a .NET application using C#, in order to sell it as a shareware and/or as a full package, so I'll need a good way to protect it against piracy. I know some ways to protect...
1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
7
by: Boni | last post by:
Dear all, in order to protect my assembly component from decompilation I implemented following schema: I created mixed mode C++ project wich has managed cProxy class and unmanaged cMemLoader....
1
by: musosdev | last post by:
Hi I've got a project I've just run through the conversion wizard, and it's giving me a few headaches. I've got a user control which has controls referrenced from its calling page...
0
by: Joe Reggae | last post by:
I know just enough about c# Windows forms development to be dangerous and am encountering a problem in VS2003 that I don't understand. In the class declaration of a form (which several forms...
2
by: sck10 | last post by:
Hello, I am getting the following error: fvServiceIdea_ItemUpdating_Validate(object, System.Web.UI.WebControls.FormViewUpdateEventArgs)' is inaccessible due to its protection level. Below...
1
by: Nosferatum | last post by:
I need to query a database for users with password and retrieve these with a third variable, "level". That's easy. username, password, level If entered username and password exist, get these...
0
by: KhoaNguyen | last post by:
Hi, When i compiled these two source files, it gives me an error saying: Inaccesssible Due to its protection level. ------------Base Class----------------- using System; using...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.