A Disk Quota code that uses ASP. NET to operate on com.

Source: Internet
Author: User

Using system;

Using diskquotatypelibrary;

Namespace ex3cut3. Libraries {///


///
///
Public class quotaclass {private diskquotacontrolclass _ diskquotacontrol;

// This path as to be in this format or
// Else is going to give an error of invalid path
Private const string filesharevolume = @ "// server/C $ /";
Private const int mbtobytes = 1048576;

Public diskquotacontrolclass diskquotacontrol
{
Get
{
If (this. _ diskquotacontrol = NULL)
{
This. _ diskquotacontrol = new diskquotacontrolclass ();
// Initializes the control to the specified path
This. _ diskquotacontrol. initialize (filesharevolume, true );
}
Return this. _ diskquotacontrol;
}
}

Public quotaclass ()
{
}

///


/// Adds a user to the quota entries of the volume
///
///The name of the user to add
///The domain that the user uses to logon
///The quota limit of this user
Public void add (string username, string userdomain, int quotalimit)
{
Didiskquotauser dskuser = NULL;
// In some cases if you use name resolution,
// The application will give an error.
This. diskquotacontrol. usernameresolution =
Usernameresolutionconstants. dqresolvenone;
// Here we had the user to the quotas entrys
// The volume, we use user@domain.net the logon name of the user.
// You can use the domain/user or just the user,
// But in like this works faster
Dskuser = This. diskquotacontrol. adduser (
User. samaccountname + "@" + User. domain );
// Here we set the limit of the quota, this is
// Prepared to receive MB so I convert it to bytes
Dskuser. quotalimit = (INT) quotalimit * mbtobytes;
// Here is the set of the warning limit
Dskuser. quotathreshold = (INT) (quotalimit/1.2) * mbtobytes;
Dskuser = NULL;
}

///


/// Removes the user form the quota entries list
///
///
Public void remove (string username)
{
// Here we just use the user, and invoke
// The method deleteuser from the control
This. diskquotacontrol. deleteuser (this. getuser (username ));
}

///


/// A private function to return the user object
///
///The User Name
/// A didiskquotauser object
/// Of the specified user
Private didiskquotauser getuser (string username)
{
// Invokes the method to find a user in a quota entry list
Return this. diskquotacontrol. finduser (username );
}

///


/// Gets the quota of the user
///
///The User Name
/// A formated string of the quota
/// Limit of the user
Private string getquota (string username)
{
// Here we return the text of the quota limit
// 0.0 bytes, 0.0 kb, 0.0 MB etc
Return this. getuser (username). quotalimittext;
}

///


/// Gets the quota currently used by the user
///
///The User Name
/// A formated string of the quota
/// Used by the user
Private string getquotaused (string username)
{
Return this. getuser (username). quotausedtext;
}

///


/// Change the quota of a specified user
///
///The User Name
///The new quota limit of the user
Private void changequota (string username, int quotalimit)
{
Didiskquotauser dskuser = This. getuser (username );
Dskuser. quotalimit = quotalimit * Support. constants. convertbtomb;
Dskuser. quotathreshold = (quotalimit/1.2)
* Support. constants. convertbtomb;
}
}
}

Note: 1. This operation COM must first reference a com Interactive Operation RWC. First, add the reference diskquotatypelibrary.

2. Add it to the top of ASP. NET.

3. If you want to operate COM in ASP. NET, you must have sufficient permissions, but ASP. NET is insufficient. Therefore, you must add this line to Web. config. Of course, you can also use other methods to grant permissions.

4. OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.