Winform

/// <summary>
///Copy or cut files to clipboard (method)
/// </summary>
///< param name = "files" > file path array to be added to the clipboard < / param >
///< param name = "cut" > whether to cut true means to cut and false means to copy < / param >
public static void CopyToClipboard(string[] files, bool cut)
{
    if (files == null) 
        return;

    IDataObject data = new DataObject(DataFormats.FileDrop, files);

    MemoryStream memo = new MemoryStream(4);

    byte[] bytes = new byte[] { (byte)(cut ? 2 : 5), 0, 0, 0 };

    memo.Write(bytes, 0, bytes.Length);

    data.SetData("Preferred DropEffect", memo);

    Clipboard.SetDataObject(data);
}


/// <summary>
///Get the list of files in the clipboard (method)
/// </summary>
/// <returns>System. Collections. List < string > returns the set of file paths in the clipboard < / returns >
public static List<string> GetClipboardList()
{
    List<string> clipboardList = new List<string>();

    IDataObject dataObject = Clipboard.GetDataObject();

    if (dataObject.GetDataPresent(DataFormats.FileDrop))
    {
        System.Collections.Specialized.StringCollection sc = Clipboard.GetFileDropList();

        for (int i = 0; i < sc.Count; i++)
        {
            string listfileName = sc[i];

            clipboardList.Add(listfileName);
        }
    }

    return clipboardList;
}


/// <summary>
///Get the list of files in the clipboard (method)
/// </summary>
/// <param name="cut">true:剪切;false:复制</param>
/// <returns>System. Collections. List < string > returns the set of file paths in the clipboard < / returns >
public static List<string> GetClipboardList(out bool cut)
{
    List<string> clipboardList = new List<string>();

    cut = false;

    IDataObject dataObject = Clipboard.GetDataObject();

    if (dataObject.GetDataPresent(DataFormats.FileDrop))
    {
        MemoryStream memoryStream = (MemoryStream)dataObject.GetData("Preferred DropEffect", true);

        DragDropEffects dragDropEffects = (DragDropEffects)memoryStream.ReadByte();

        if ((dragDropEffects & DragDropEffects.Move) == DragDropEffects.Move)
        {
            cut = true;
        }

        StringCollection sc = Clipboard.GetFileDropList();

        for (int i = 0; i < sc.Count; i++)
        {
            string listfileName = sc[i];

            clipboardList.Add(listfileName);
        }
    }

    return clipboardList;
}

Static files, such as HTML, CSS, pictures and JavaScript, will be directly provided to clients by asp.net core applications.

Static file service

//Install staticfiles package
Install-Package Microsoft.AspNetCore.StaticFiles

In the application, we can enable the static file service by configuring the staticfiles middleware, and add the staticfiles middleware to the pipeline:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseStaticFiles(); 
}

Static files are usually located in the web root (/wwwroot) folder. We usually set the current directory of the project as content root, so that the web root of the project can be defined in the development phase.

  • http://(app)/(fileName)
  • http://localhost:9189/1.jpg
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"MyStaticFiles")),
        RequestPath = new PathString("/StaticFiles")
    });
}

Static files can also be saved in any folder under the root directory of the website, and can be accessed through the relative root path.

  • http://(app)/StaticFiles/(fileName)
  • http://localhost:9189/StaticFiles/1.jpg

Asp.net core's built-in service container is intended to provide the basic requirements of the framework on which most client applications are built.

Of course, developers can easily replace the default container with their preferred container. The ConfigureServices method usually returns void , but if its signature is changed to return IServiceProvider, a different container can be configured and returned.

There are many IOC containers to choose from in the development process. Here is an example of using the Autofac package.

1. Install Autofac in the project

Install-Package Autofac
Install-Package Autofac.Extensions.DependencyInjection

2. Configure the container in configureservices and return iserviceprovider

public class Startup
{
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
      // Add Autofac
      var containerBuilder = new ContainerBuilder();
      containerBuilder.Populate(services);
      containerBuilder.RegisterModule<AutofacModule>();
      Startup.AutofacContainer = containerBuilder.Build();
      return new AutofacServiceProvider(Startup.AutofacContainer);
    }

    public static IContainer AutofacContainer { get; set; }
}

Note: the order of Populate method and RegisterModule is to register services in the aotofac container. During configuration, the same interface will be overwritten by the later registered services.