COMPUTER_LZY

要输就输给追求,要嫁就嫁给幸福

导航

统计

公告

2012年5月29日 #

Retrieving the COM class factory for component with CLSID {00024500-0000-000 (未成功)

这两天用ASP.NET写一个导入EXCEL数据到ORACLE的程序,调试通过,但是部署到服务器上就不能用了。

Retrieving the COM class factory for component with CLSID {00024500-0000-000

 

后来终于解决:

在服务器上,

1,运行dcomcnfg打开组件服务

2,依次展开"组件服务"->"计算机"->"我的电脑"->"DCOM配置"

3,找到"Microsoft Excel应用程序"

右键打开属性对话框

点击"安全"选项卡,

把"启动和激活权限","配置权限",都选择为自定义,

然后依次点击它们的编辑,把ASPNET添加进去,并加入所有的权限...

 

 

 

 由于之前的导入Excel文件时正常的,后来因为某个原因吧系统时间修改成了2008年,结果就出现了这种情况。电脑重启后把时间又修改为现在时间后就没有出现这个问题了。

 

posted @ 2012-05-29 08:43 RGY_LZY 阅读(6) 评论(0) 编辑

2012年5月25日 #

silverlight Web.config connectionstring

此时打开web.config文件,模板已经自动生成如下设置:

 

  <connectionStrings>

    <add name="ApplicationServices"

         connectionString="data source=./SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|/aspnetdb.mdf;User Instance=true"

         providerName="System.Data.SqlClient" />

  </connectionStrings>

 

    <membership>

      <providers>

        <clear/>

        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"

             enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"

             maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"

             applicationName="/" />

      </providers>

    </membership>

 

 

 

  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="data source=SOFTWARETEAM;Integrated Security=SSPI;Initial Catalog=aspnetdb"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
SOFTWARETEAM为数据库名,其它参数的解释,可以参考http://blog.csdn.net/cxy666/archive/2009/11/06/4776906.aspx
  • 如果使用工程App_Data目录下的数据库(假设为TestDB.mdf),则需要进行如下步骤: 
  1. 使用sql server(express)生成数据库文件,指定目录为App_Data;
  2. 停止sql server(express),并备份上步中创建的数据库;
  3. 启动sql server(express),并删除创建的数据库;
  4. 将备份的数据库拷贝至App_Data;(不采用如上几步的话,在使用asp.net Web Site Administration Tool进行配置的时候,会提示数据库文件被另外的进程占用)
  5. 修改<connectionStrings>如下:
      <connectionStrings>
        <add name="ApplicationServices"
             connectionString="data source=SOFTWARETEAM;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|/TestDB.mdf"
             providerName="System.Data.SqlClient" />
      </connectionStrings>

    posted @ 2012-05-25 13:56 RGY_LZY 阅读(4) 评论(0) 编辑

    2012年5月16日 #

    Export Silverlight DataGrid to Excel XML/CSV


     

     

    using System;

    using System.Windows;

    using System.Windows.Data;
    using System.Windows.Media;
    using System.Windows.Controls;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Reflection;
    using System.Xml.Linq;

    public static class DataGridExtensions 

        public static void Export(this DataGrid dg)
        {
            ExportDataGrid(dg);
        }

        public static void ExportDataGrid(DataGrid dGrid)
        {
            SaveFileDialog objSFD = new SaveFileDialog() { DefaultExt = "csv", Filter = "CSV Files (*.csv)|*.csv|Excel XML (*.xml)|*.xml|All files (*.*)|*.*", FilterIndex = 1 };
            if (objSFD.ShowDialog() == true)
            {
                string strFormat = objSFD.SafeFileName.Substring(objSFD.SafeFileName.IndexOf('.') + 1).ToUpper();
                StringBuilder strBuilder = new StringBuilder();
                if (dGrid.ItemsSource == nullreturn;
                List<string> lstFields = new List<string>();
                if (dGrid.HeadersVisibility == DataGridHeadersVisibility.Column || dGrid.HeadersVisibility == DataGridHeadersVisibility.All)
                {
                    foreach (DataGridColumn dgcol in dGrid.Columns)
                        lstFields.Add(FormatField(dgcol.Header.ToString(), strFormat));
                    BuildStringOfRow(strBuilder, lstFields, strFormat);
                }
                foreach (object data in dGrid.ItemsSource)
                {
                    lstFields.Clear();
                    foreach (DataGridColumn col in dGrid.Columns)
                    {
                        string strValue = "";                    
                        Binding objBinding = null;
                        if (col is DataGridBoundColumn)
                            objBinding = (col as DataGridBoundColumn).Binding;
                        if (col is DataGridTemplateColumn)
                        {
                            //This is a template column... let us see the underlying dependency object
                            DependencyObject objDO = (col as DataGridTemplateColumn).CellTemplate.LoadContent();
                            FrameworkElement oFE = (FrameworkElement)objDO;
                            FieldInfo oFI = oFE.GetType().GetField("TextProperty");
                            if (oFI != null)
                            {
                                if (oFI.GetValue(null) != null)
                                {
                                    if (oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)) != null)
                                        objBinding = oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)).ParentBinding;
                                }
                            }
                        }
                        if (objBinding != null)
                        {
                            if (objBinding.Path.Path != "")
                            {
                                PropertyInfo pi = data.GetType().GetProperty(objBinding.Path.Path);
                                if (pi != null) strValue = pi.GetValue(data, null).ToString();
                            }
                            if (objBinding.Converter != null)
                            {
                                if (strValue != "")
                                    strValue = objBinding.Converter.Convert(strValue, typeof(string), objBinding.ConverterParameter, objBinding.ConverterCulture).ToString();
                                else
                                    strValue = objBinding.Converter.Convert(data, typeof(string), objBinding.ConverterParameter, objBinding.ConverterCulture).ToString();
                            }
                        }
                        lstFields.Add(FormatField(strValue,strFormat));
                    }
                    BuildStringOfRow(strBuilder, lstFields, strFormat);
                }
                StreamWriter sw = new StreamWriter(objSFD.OpenFile());
                if (strFormat == "XML")
                {
                    //Let us write the headers for the Excel XML
                    sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                    sw.WriteLine("<?mso-application progid=\"Excel.Sheet\"?>");
                    sw.WriteLine("<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\">");
                    sw.WriteLine("<DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\">");
                    sw.WriteLine("<Author>Arasu Elango</Author>");
                    sw.WriteLine("<Created>" +  DateTime.Now.ToLocalTime().ToLongDateString() + "</Created>");
                    sw.WriteLine("<LastSaved>" + DateTime.Now.ToLocalTime().ToLongDateString() + "</LastSaved>");
                    sw.WriteLine("<Company>Atom8 IT Solutions (P) Ltd.,</Company>");
                    sw.WriteLine("<Version>12.00</Version>");
                    sw.WriteLine("</DocumentProperties>");
                    sw.WriteLine("<Worksheet ss:Name=\"Silverlight Export\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\">");
                    sw.WriteLine("<Table>");
                }
                sw.Write(strBuilder.ToString());
                if (strFormat == "XML")
                {
                    sw.WriteLine("</Table>");
                    sw.WriteLine("</Worksheet>");
                    sw.WriteLine("</Workbook>");
                }
                sw.Close();
            }
        }
        private static void BuildStringOfRow(StringBuilder strBuilder, List<string> lstFields, string strFormat)
        {
            switch (strFormat)
            {
                case "XML":
                    strBuilder.AppendLine("<Row>");
                    strBuilder.AppendLine(String.Join("\r\n", lstFields.ToArray()));
                    strBuilder.AppendLine("</Row>");
                    break;
                case "CSV":
                    strBuilder.AppendLine(String.Join(",", lstFields.ToArray()));
                    break;
            }
        }
        private static string FormatField(string data, string format)
        {
            switch (format)
            {
                case "XML":
                    return String.Format("<Cell><Data ss:Type=\"String\">{0}</Data></Cell>", data);
                case "CSV":
                    return String.Format("\"{0}\"", data.Replace("\"""\"\"\"").Replace("\n""").Replace("\r"""));
            }
            return data;
        }
    }

    posted @ 2012-05-16 16:24 RGY_LZY 阅读(10) 评论(0) 编辑

    Microsoft.Silverlight.CSharp.targets

    报错:

    Unable to read the project file 'XNTVOD.AdminClient.csproj'. C:\Path\To\MyProject.csproj(593,3): The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. 

     

    解决: 

    The file that's missing ships in the Silverlight 4 SDK. You can either install just the Silverlight 4 SDK, or re-install the entire Silverlight 4 Tools for VS2010 package (which will re-install the developer runtime, SDK, a hotfix for VS2010, the Silverlight 4 Tools package, and WCF RIA Services).

    posted @ 2012-05-16 13:48 RGY_LZY 阅读(7) 评论(0) 编辑

    2012年5月14日 #

    SilverLight网站的发布

    修改IIS:

     配置 MIME类型

    .bin sl/octet-stream

    .xaml application/xaml+xml

    .xap xapapplication/x-silverlight

     

    将整个项目Web下的所有文件Copy到IIS的虚拟目录下面就可以了。

     

     

    问题:

    为什么直接在VS2010中直接右键publish老是出错呢?不解

     报错内容:

    Error 1 Web deployment task failed.(The metabase path '/lm/w3svc/<siteid>/ROOT/..' is not supported. Paths must be of the format '/lm/w3svc/<siteid>/ROOT/...'.)
    The metabase path '/lm/w3svc/<siteid>/ROOT/..' is not supported. Paths must be of the format '/lm/w3svc/<siteid>/ROOT/...'.
    The metabase key '/lm/w3svc/<siteid>/ROOT/..' could not be found.
    系统找不到指定的路径。 (Exception from HRESULT: 0x80070003) 0 0 SilverlightApplication1.Web

     

    posted @ 2012-05-14 16:36 RGY_LZY 阅读(4) 评论(0) 编辑

    2012年4月27日 #

    ASP.NET 读取本地Excel

    在网页中选择本地Excel文件并获取文件内容,需要将该文件首先上传到服务器上,然后再根据该文件在服务器上的地址获取该文件的内容,代码如下 :

     /// <summary>
        
    /// 上传文件的根目录
        
    /// </summary>
        private string bootPath = HttpContext.Current.Request.PhysicalApplicationPath + "Files\\";
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (file_note.HasFile)
            {
                //判断文件是否小于10Mb  
                if (file_note.PostedFile.ContentLength < 10485760)
                {
                    string fileForm = file_note.FileName.Split('.')[file_note.FileName.Split('.').Length - 1];
                    string filePath = bootPath + string.Format("{0:yyyyMMddHHmmss}", DateTime.Now) + "." + fileForm;
                    file_note.PostedFile.SaveAs(filePath);

                    DataSet a = CommonClassLib.ExcelHelper.ReturnDataSetFromExcelFile(filePath); 

                    Response.Write("<script language:javascript>javascript:window.opener=null;window.close();</script>");
                }
            }    }  

     

     

    posted @ 2012-04-27 14:22 RGY_LZY 阅读(12) 评论(0) 编辑

    2012年4月26日 #

    GridView Repeater导出PDF-Word-Excel

    摘要: #regionExporttoWord,ExcelandPDFprotectedvoidbtnword_Click(objectsender,EventArgse){Response.AddHeader("content-disposition","attachment;filename=FileName.doc");Response.Cache.SetCacheability(HttpCacheability.NoCache);Response.ContentType="application/vnd.word";System.IO阅读全文

    posted @ 2012-04-26 10:24 RGY_LZY 阅读(17) 评论(0) 编辑

    2012年4月10日 #

    GridView中实现CheckBox的全选

    摘要: 用服务器端的方法:在页面上放一个gridview控件,配置好数据源,编辑列,添加一个模版列,再编辑模版,放入一个checkbox控件。代码如下:<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="AreaID" DataSourceID="SqlDataSource1"> <Columns> &l阅读全文

    posted @ 2012-04-10 10:08 RGY_LZY 阅读(6) 评论(0) 编辑

    2012年4月9日 #

    ASP.NET AutoPostBack 弹出新页面

    摘要: 在<head></head>之间加入 <base target="_self"/>即可阅读全文

    posted @ 2012-04-09 15:35 RGY_LZY 阅读(20) 评论(0) 编辑

    2012年3月29日 #

    ASP.Net 刷新页面

    摘要: 第一:private void Button1_Click( object sender, System.EventArgs e ){ Response.Redirect( Request.Url.ToString( ) );}第二:private void Button2_Click( object sender, System.EventArgs e ){ Response.Write( " <script language=javascript>window.location.href=document.URL; </script>" );}第阅读全文

    posted @ 2012-03-29 18:36 RGY_LZY 阅读(32) 评论(0) 编辑

    仅列出标题  下一页