小编Moh*_*hir的帖子

在C#中创建没有只读属性的文件夹

我正在尝试从我的应用程序在'c:\'文件夹中创建一个文件夹(例如:c \),但此文件夹始终以"只读"权限创建.

我尝试过以下代码,但仍然无法更改属性.请帮我.,

方法1

var di = new DirectoryInfo(temppath);
File.SetAttributes(temppath, FileAttributes.Normal);
File.SetAttributes(temppath, FileAttributes.Archive); */
Run Code Online (Sandbox Code Playgroud)

方法2

di.Attributes = di.Attributes | ~FileAttributes.ReadOnly;
File.SetAttributes(temppath, File.GetAttributes(temppath) & ~FileAttributes.ReadOnly);
Run Code Online (Sandbox Code Playgroud)

方法3

foreach (string fileName in System.IO.Directory.GetFiles(temppath))
{
    System.IO.FileInfo fileInfo = new System.IO.FileInfo(fileName);

    fileInfo.Attributes |= System.IO.FileAttributes.ReadOnly;
    // or
    fileInfo.IsReadOnly = false;
}
Run Code Online (Sandbox Code Playgroud)

所有这些方法都不起作用或只是更改文件的属性而不是文件夹.

c# file

5
推荐指数
1
解决办法
5373
查看次数

剪贴板始终为空

我按下Print Screen按钮后试图截取我的显示器.使用下面的代码我试图检查剪贴板中是否有任何内容.如果是这样,我试图将其保存在c:\文件夹中.但Clipboard.ContainsImage()总是返回0,但是当我粘贴在Paint中时,会有一个图像.

我在某地读到这可以通过代表来完成.请让我知道如何做到这一点.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace Example2
{
    class Program
    {
        static void Main(string[] args)
        {
            if (Clipboard.ContainsImage())
            {
                //System.Drawing.Image screenshot = new System.Drawing.Image();
                Image screenshot = Clipboard.GetImage();

                screenshot.Save("c:\\screenshot.jpg");
            }
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# clipboard

1
推荐指数
1
解决办法
1192
查看次数

标签 统计

c# ×2

clipboard ×1

file ×1