Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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:

C#
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();
            }
        } 
    }
   
}


Please help me with this.

What I have tried:

I'm unaware of this how to handle in asp.net.
Posted
Updated 14-Apr-16 9:09am
Comments
Richard Deeming 14-Apr-16 12:36pm    
The code is running on the server. It's only going to list the drives on the server, not the drives on the client.

And in anticipation of your next question: no, you can't list the drives on the client. Websites don't have that level of access to the client hardware; if they did, it would be a major security vulnerability.
Sergey Alexandrovich Kryukov 14-Apr-16 14:36pm    
5ed. Honestly, post a formal answer. We cannot possibly help this person more. It sounds hopeless, considering the previous "question". Let's at least close the issue with a valid answer like yours.

I would ask the inquirer to stop asking this and similar questions. Instead, I would advise to learn what Web technologies do, in principle. Presently, without having a clue on what it is, it's just waste of time.

—SA

1 solution

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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Apr-16 17:53pm    
Thank you for answering. I really hope it can close the "issue". 5ed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900