关于磁盘驱动器和空间 [英] Regarding disk drives and spaces

查看:85
本文介绍了关于磁盘驱动器和空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我完全改变了我的问题所以创建了一个新问题。



我已经编写了一个代码,它正在读取我的计算机中的驱动器,但是当我使用数据线将我的手机连接到我的笔记本电脑并刷新页面时,它只显示我的手机驱动器。实际上它应该显示我的驱动器和移动驱动器,但它只显示1.



如何重新获得网络位置(映射驱动器)磁盘大小?



以下是我的代码:



Hi all,

I have changed my question completly so created a new question.

I have written a code where it's reading the drives in MY COMPUTER but when i conncet my mobile to my laptop with data cable and refresh the page, it's displaying only my mobile's drive. Actually it should show both my drives and mobile drive but it's showin only 1.

And how to reteive the NETWORK LOCATION (mapped drives) disk size?

Below is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.Common;
using System.Data;


public partial class DriveThreshold : System.Web.UI.Page
{
    class Report
{
        public static void Main()
        {
            
        }
}

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }



    protected void DriveInfo_Click(object sender, EventArgs e)
    {

        DriveInfo[] allDrives = DriveInfo.GetDrives();

        foreach (DriveInfo d in allDrives)
        {
            Console.WriteLine("Drive {0}", d.Name);
            Console.WriteLine("Drive type: {0}", d.DriveType);
            if (d.IsReady == true)
            {
                Console.WriteLine("Volume label: {0}", d.VolumeLabel);
                Console.WriteLine("File system: {0}", d.DriveFormat);
                Console.WriteLine("Available space to current user:{0, 15} bytes", d.AvailableFreeSpace);

                Console.WriteLine("Total available space:          {0, 15} bytes", d.TotalFreeSpace);

                Console.WriteLine("Total size of drive:            {0, 15} bytes ", d.TotalSize);

                DataTable dt = new DataTable();
                dt.Columns.Add("Drive");
                dt.Columns.Add("Drive type");
                dt.Columns.Add("Volume label");

                dt.Columns.Add("Available space to current user");
                dt.Columns.Add("Total available space");
                dt.Columns.Add("Total size of drive");


                DataRow dr = dt.NewRow();
                dr[0] = d.Name;
                dr[1] = d.DriveType;
                dr[2] = d.VolumeLabel;

                dr[3] = d.AvailableFreeSpace;
                dr[4] = d.TotalFreeSpace;
                dr[5] = d.TotalSize;

                dt.Rows.Add(dr);
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
        } 
    }
   
}





请帮帮我有了这个。



我尝试了什么:



我是不知道如何在asp.net中处理。



Please help me with this.

What I have tried:

I'm unaware of this how to handle in asp.net.

推荐答案

如评论中所述,该代码在服务器上运行 。它列举了服务器上的驱动器,客户端上的驱动器。



网站无法访问客户端的硬件,因为将是一个主要的安全漏洞。您无法枚举客户端的驱动器,无论您是尝试在服务器端代码还是客户端javascript中执行此操作。



如果您尝试枚举服务器的驱动器,然后您还需要记住代码将以不同的身份在不同的会话中运行。映射驱动器特定于会话,因此ASP.NET代码将无法看到为您的会话映射的驱动器。
As mentioned in the comments, that code is running on the server. It is enumerating the drives on the server, not the drives on the client.

Websites have no access to the client's hardware, because that would be a major security vulnerability. You can't enumerate the client's drives, whether you're trying to do it in server-side code or client-side javascript.

If you are trying to enumerate the server's drives, then you also need to remember that the code will be running in a different session, under a different identity. Mapped drives are specific to a session, so drives mapped for your session will not be visible to ASP.NET code.


这篇关于关于磁盘驱动器和空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆