如何使用C#在oracle数据库中创建zip文件 [英] How do create zip file in oracle database using C#

查看:55
本文介绍了如何使用C#在oracle数据库中创建zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用表名中的c#在数据库中创建zip文件。



谢谢



< pre lang =xml> < 表格 id = form1 < span class =code-attribute> runat = server >
< h3 style = 颜色:#0000FF; font-style:italic > 创建Zip ASP.NET < / h3 >
< div 样式 = 身高:121px >
< asp:FileUpload ID = FileUpload runat = 服务器 / >
< br / >
< br < span class =code-attribute> / >
< asp:按钮 ID = bttnupload runat = server 文字 = 上传文件 字体粗体 = True

onclick = bttnupload_Click / >
& nbsp;& nbsp;& nbsp;
< asp:按钮 ID = bttnzip runat = 服务器 文字 = 创建Zip Font-Bold =

onclick = bttnzip_Click / >
& nbsp;& nbsp; &安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;
< br < span class =code-keyword> / >
< br / >
< asp:Label ID = lbltxt runat = server ForeColor = #CC0000 > < / asp:Label >
< / div >
< / form >



======================= =============================================

C#



//这段代码可以在本地pc上创建。我需要在数据库表中创建

  protected   void  bttnupload_Click( object  sender,EventArgs e)
{
if ( FileUpload.HasFile)
{
string filename = Path.GetFileName(FileUpload.PostedFile.FileName);
string pathname = Server.MapPath( 〜/ zipa / + filename);
FileUpload.SaveAs(pathname);
lbltxt.Text = 文件上传成功;
}
}
受保护 void bttnzip_Click( object sender,EventArgs e)
{
try
{
< span class =code-keyword> string pathname = Server.MapPath( 〜/ zipa / );
string [] filename = Directory.GetFiles(pathname);
使用(ZipFile zip = new ZipFile())
{
zip.AddFiles(filename, file);
zip.Save(Server.MapPath( 〜/ zipa.zip));
lbltxt.Text = Zip File Created;
}
}
catch (例外情况)
{
lbltxt.Text = ex.Message;
}
}

解决方案

ZIP与数据库无关,除非您想将ZIP数据存储为一个 blob ,这将是一个完全非结构化的实体,几乎击败了关系数据库的目的。

要在.NET代码中使用ZIP,你可以使用几个选项,例如#ziplib,DotNetZip,以及着名的7-zip的.NET包装器。请参阅:

https://dotnetzip.codeplex.com [ ^ ],

http://www.4guysfromrolla.com/articles/092910-1.aspx [ ^ ]

和我过去的答案:

两个文件夹之间的比较 [ ^ ],

使用vb.net提取文件rar [ ^ ]。



参见这个答案:将文件夹压缩成多个zip文件 [ ^ ]。



-SA

How to create zip file in database using c# from the tablename.

Thanks

 <form id="form1" runat="server">
<h3 style="color: #0000FF; font-style: italic"> Create Zip in ASP.NET</h3>
    <div style="height: 121px">
        <asp:FileUpload ID="FileUpload" runat="server" />
        <br />
        <br />
        <asp:Button ID="bttnupload" runat="server" Text="Upload File" Font-Bold="True"

            onclick="bttnupload_Click" />
&nbsp;&nbsp;&nbsp;
        <asp:Button ID="bttnzip" runat="server" Text="Create Zip" Font-Bold="True"

            onclick="bttnzip_Click" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <asp:Label ID="lbltxt" runat="server" ForeColor="#CC0000"></asp:Label>
    </div>
    </form>


====================================================================
C#

//this code work to create in local pc. I need to create in database table

protected void bttnupload_Click(object sender, EventArgs e)
    {
        if (FileUpload.HasFile)
        {
            string filename = Path.GetFileName(FileUpload.PostedFile.FileName);
            string pathname = Server.MapPath("~/zipa/" + filename);
            FileUpload.SaveAs(pathname);
            lbltxt.Text = "File Upload Successfully";
        }
    }
    protected void bttnzip_Click(object sender, EventArgs e)
    {
        try
        {
            string pathname = Server.MapPath("~/zipa/");
            string[] filename = Directory.GetFiles(pathname);
            using (ZipFile zip = new ZipFile())
            {
                zip.AddFiles(filename, "file");
                zip.Save(Server.MapPath("~/zipa.zip"));
                lbltxt.Text = "Zip File Created";
            }
        }
        catch (Exception ex)
        {
            lbltxt.Text = ex.Message;
        }
    }

解决方案

ZIP has nothing to do with databases, unless you want to store ZIP data as a blob, which would be a totally non-structural entity pretty much defeating the purpose of relational databases.
To work with ZIP in your .NET code, you can use several options, such as #ziplib, DotNetZip, and also a .NET wrapper of the famous 7-zip. Please see:
https://dotnetzip.codeplex.com[^],
http://www.4guysfromrolla.com/articles/092910-1.aspx[^]
and my past answers:
Compare between two folders[^],
Extract file rar with vb.net[^].

See also this answer: compress a folder into multiple zip files[^].

—SA


这篇关于如何使用C#在oracle数据库中创建zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆