Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FileCatalog
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void Form1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;                            //设置拖放操作中目标放置类型为复制
            String[] str_Drop = (String[])e.Data.GetData(DataFormats.FileDrop, true);//检索数据格式相关联的数据
            MessageBox.Show(str_Drop[0]);
        }
    }
}

Form1.Designer.cs

namespace FileCatalog
{
    partial class Form1
    {
        /// <summary>
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

/// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

#region Windows 窗体设计器生成的代码

/// <summary>
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            //
            // Form1
            //
            this.AllowDrop = true;
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(292, 99);
            this.Name = "Form1";
            this.Text = "获取文件目录";
            this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter);
            this.ResumeLayout(false);

}

#endregion
    }
}

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace FileCatalog
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

C#获取文件目录的更多相关文章

  1. python 获取文件目录位置

    test.py import os print('***获取当前目录***') print(os.getcwd()) print(os.path.abspath(os.path.dirname(__f ...

  2. shell中获取文件目录方法

    1.``:表示执行对应的命令,嵌套时使用`\`\``,注意\进行转义,同时执行多个命令时使用:隔开file=`cd "\`dirname $0\`";pwd`echo $file ...

  3. PHP获取文件目录dirname(__FILE__),getcwd()

    以discuz x2.5为例 D:/www/upload2.5/test.php D:/www/upload2.5/source/class/class_test.php test.php文件如下 & ...

  4. java中获取文件目录

    1. web项目得到部署的目录路径(最后包含"/"或"\"): xxx(HttpServletRequest request) { String strDirP ...

  5. Windows 下c获取文件目录

    由于要插数据库,构建sql语句,需要文件名,在网上找了半天,无奈都是Linux下的专用函数,伤心,,还有那个下载URL ,还木搞好,就要走啦,心焦哇 #include<iostream> ...

  6. Java学习-009-文件名称及路径获取实例及源代码

    此文源码主要为应用 Java 获取文件名称及文件目录的源码及其测试源码.若有不足之处,敬请大神指正,不胜感激!源代码测试通过日期为:2015-2-3 00:02:27,请知悉. Java获取文件名称的 ...

  7. 详解php 获取文件名basename()函数的用法

    PHP 中basename()函数给出一个包含有指向一个文件的全路径的字符串,此函数返回基本的文件名,本篇文章收集了关于使用PHP basename()函数获取文件名的几篇文章,希望对大家理解使用PH ...

  8. IndexOf、LastIndexOf、Substring的用法及C# foreach 中获取索引index的方法

     String.IndexOf String.IndexOf 方法 (Char, Int32, Int32)报告指定字符在此实例中的第一个匹配项的索引.搜索从指定字符位置开始,并检查指定数量的字符位置 ...

  9. System.getProperty("user.dir")获取的到底是什么路径?

    一直用System.getProperty("user.dir")来获取文件目录,我在执行单个方法调试和执行测试脚本的时候碰到一个问题, 我写了一个类ElementInitiali ...

随机推荐

  1. Hdu2602 Bone Collector (01背包)

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  2. 鼠标右键vsCode打开

    有时候在安装vscode不会出现鼠标右键用vscode打开的情况: 最终要实现的样子: 解决办法如下步骤: 1.安装vscode: 2.新建一个“.reg”为后缀的文件: 3.把下面内容复制到文件中: ...

  3. 使用pm2-zabbix监控node工程

    环境 centos 7 zabbix 3.2.6 node 4.4.3 安装 # wget http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix ...

  4. Linux-Centos7 安装图形界面

    1.首先安装X(X Window System),命令为 :yum groupinstall "X Window System" 回车(注意有引号) 2.查看桌面列表 : yum ...

  5. 【Alpha】Scrum Meeting 3

    目录 简介: 工作内容: 工作修改: 燃尽图: 难点: 后期任务: 签入记录 团队讨论照片: 简介: 地点:J1-316 时间:4月3日星期四,晚上七点 会议目的:讨论大家此次的分工 工作内容: 陈治 ...

  6. bzoj 1835 base 基站选址 - 动态规划 - 线段树

    题目传送门 需要高级权限的传送门 题目大意 有$n$个村庄坐落在一条直线上,第$i \ \ \ (i>1)$个村庄距离第$1$个村庄的距离为$D_i$.需要在这些村庄中建立不超过$K$个通讯基站 ...

  7. Bootstrap3基础 text-right/left/center 设置标题右对齐、左对齐、居中

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  8. RPM 包的构建 - SPEC 基础知识

    spec 文件 制作 rpm 软件包并不是一件复杂的工作,其中的关键在于编写软件包的 spec 描述文件. 要想制作一个 rpm 软件包就必须写一个软件包描述文件 spec.这个文件中包含了软件包的诸 ...

  9. non-ZenoAndAcceptingLocation

    PATTERN系列的番外篇 对non-Zeno的概念进行了明晰 accepting:if infinitely often the same state non-Zeno:if time diverg ...

  10. JS中如何判断对象是对象还是数组

    JS中如何判断对象是对象还是数组 一.总结 一句话总结:typeof Array.isArray === "function",Array.isArray(value)和Objec ...