UNC Directory browser with aspx

D

dkode8

Hello,

I am creating an application that uses impersonation to log a user into
our domain and then show them the contents of their network share where
they store their files.

I have all the permissions and impersonation working correctly, Now I
have hit a snag on how to get my idea to work..

Right now i have default.aspx, and Directory.cs

inside Directory.cs is the class DirNavigator which has two public
properties: userPath, Current

userPath = full UNC path to their network share
Current = full path to the folder they are browsing after the userPath

I.E.:
userPath = "\\server\dkode"
Current = "Folder1\Folder2\Folder3

so once they are appended together,
\\server\dkode\Folder1\Folder2\Folder3

each time they browse to a different folder, it appends or subtracts
from Current.

The problem arises from the fact that I am storing dirNavigator
instance in the session, each time default.aspx loads, I show the
appropriate folder. When they click the back button, dirNavigator is
not updated and when they click on a different folder, it still thinks
they are one folder deeper then they are.

How else can I store the instance of dirNavigator so that it updates
itself and always has the current path they are working with. maybe a
hidden form variable? the folders can get pretty deep so I don't want
to pass the whole folder path in the querystring...
any suggestions?

Thank you!

DKode
 
W

William F. Robertson, Jr.

You can either place it as a hidden form variable, but I would recommend
placing the CurrentFolder into viewstate for the page. It is basically the
same as a hidden field, except it isn't a hidden field viewable by View
Source.

Also ViewState, IMO, seems easier to code against.

public string Current
{
get
{
//doing it this way will shield your implementation for checking for
null and empty string.
string s = ( string ) ViewState["Current"];
return ( s == null ) ? String.Empty : s;
}
set { ViewState["Current"] = value; }
}


You reference the item anywhere in a page through the property Current.

HTH,

bill
 
D

DKode

thank you,

what does this piece of code here do, i see its some sort of
substitution?

return ( s == null ) ? String.Empty : s;

other than that, would that solve the ie back button problem? or would
i have to format the userpath/current folder?

thanks again
 
W

William F. Robertson, Jr.

This is shorthand syntax for an if statement. I am not sure if this will
work in vb.

return ( s == null ) ? String.Empty : s;

is equivilent to:

if ( s == null )
return String.Empty;
else
return s;

When the user hits the back button they will be on a page that is displaying
a different path. When the user causes postback on the "backed" page, the
ViewState for the page will have the correct path. I am not sure entirely
what you are asking, but a page that is posted back will have the ViewState
from the page as originally sent. Just try it out and see if that is the
behavior you are expecting and wanting.

bill
 
D

DKode

ok,

really dumb question,

when I place the ViewState[] code in my dirNavigator class, it says
ViewState namespace does not exist, I added all the refernces as the
aspx page. Can you access ViewState from outside an aspx page or not?
 
W

William F. Robertson, Jr.

The ViewState is a protected property of the page. If you want to reference
the viewstate outside the page object, you will need to pass a reference
over to it.

I am not sure of your exactly implementation, but you should change this to
what you need it to do.

public class dirNavigator
{
private readonly StateBag ViewState;
publiv dirNavigator( StateBag viewState )
{
ViewState = viewState;
}
}

Now in your page code you will pass the reference to the constructor of the
class.

//in page load or where ever you instantiate it.
dirNavigator navigator = new dirNavigator( this.ViewState );

You will then be able to access the ViewState collection from your outside
class.

HTH,

bill
 
D

DKode

gotcha,

thanks for the info. i will give it a shot tonight probably.
thanks again!

DKode
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,147
Latest member
CarenSchni
Top