相关疑难解决方法(0)

如何在c#中自动删除临时文件?

如果我的应用程序关闭或崩溃,有什么方法可以确保删除临时文件?理想情况下,我想获取一个临时文件,使用它,然后忘记它.

现在我保留一个我的临时文件列表,并使用在Application.ApplicationExit上触发的事件处理程序删除它们.

有没有更好的办法?

.net c# temporary-files

55
推荐指数
5
解决办法
6万
查看次数

如何从嵌入式资源中提取文件并将其保存到磁盘?

我正在尝试使用CSharpCodeProvider编译下面的代码.该文件已成功编译,但是当我单击生成的EXE文件时,我收到错误(Windows正在搜索此问题的解决方案)并且没有任何反应.

当我使用CSharpCodeProvider编译下面的代码时,我MySql.Data.dll使用以下代码行添加了作为嵌入式资源文件:

if (provider.Supports(GeneratorSupport.Resources))
    cp.EmbeddedResources.Add("MySql.Data.dll");
Run Code Online (Sandbox Code Playgroud)

该文件已成功嵌入(因为我注意到文件大小增加).

在下面的代码中,我尝试提取嵌入的DLL文件并将其保存到System32,但下面的代码由于某种原因不起作用.

namespace ConsoleApplication1
{
    class Program
    {
        public static void ExtractSaveResource(String filename, String location)
        {
            //Assembly assembly = Assembly.GetExecutingAssembly();
            Assembly a = .Assembly.GetExecutingAssembly();
            //Stream stream = assembly.GetManifestResourceStream("Installer.Properties.mydll.dll"); // or whatever
            //string my_namespace = a.GetName().Name.ToString();
            Stream resFilestream = a.GetManifestResourceStream(filename);
            if (resFilestream != null)
            {
                BinaryReader br = new BinaryReader(resFilestream);
                FileStream fs = new FileStream(location, FileMode.Create); // Say
                BinaryWriter bw = new BinaryWriter(fs);
                byte[] ba = new byte[resFilestream.Length];
                resFilestream.Read(ba, 0, ba.Length);
                bw.Write(ba);
                br.Close();
                bw.Close(); …
Run Code Online (Sandbox Code Playgroud)

.net c# embedded-resource csharpcodeprovider

48
推荐指数
3
解决办法
7万
查看次数

嵌入式资源文件的路径

我的资源文件中有一个图标,我想引用它.

这是需要该图标文件路径的代码:

IWshRuntimeLibrary.IWshShortcut MyShortcut  ;
MyShortcut =   (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + @"\PerfectUpload.lnk");
MyShortcut.IconLocation = //path to icons path . Works if set to @"c:/icon.ico" 
Run Code Online (Sandbox Code Playgroud)

我没有外部图标文件,而是希望它找到嵌入式图标文件.就像是

MyShortcut.IconLocation  = Path.GetFullPath(global::perfectupload.Properties.Resources.finish_perfect1.ToString()) ;
Run Code Online (Sandbox Code Playgroud)

这可能吗 ?如果是这样的话?

谢谢

.net c#

17
推荐指数
1
解决办法
3万
查看次数