破宝

我是一块破破烂烂的宝贝石头。
随笔 - 94, 评论 - 1281, 引用 - 52

导航

关于

自选精华版 RECOMMENDATIONS
留言板 GUESTBOOK

本人 blog 文章、图片及其他资源等,除另有声明外,均遵循以下原则向全球(当然包括朝鲜、古巴、利比亚等国)共享:

1。欢迎转载、复制、传播、引用,但转载、复制(包括但不仅限于作为参考资料复制到本地)、传播、引用同时必须在显著位置注明作者(破宝/percyboy)和文章原始 URL 地址等信息。但商业转载、复制、传播(尤指用于图书、光盘等媒体的部分或全部),须事先征得本人的许可。

2。文章以“现状”提供,不为由于使用本站资源而造成的任何损失而负责,仅提供力所能及的咨询和参考意见。

3。关于修改:允许您将本 blog 中的资源作为参考资料复制时的一定修改,但仍须保留作者和出处信息;其他情况下的修改(包括修改后再发布),须和本人确认许可。
 

标签

每月存档

最新留言

广告

About GridView, HyperLinkField, UrlEncode

I suppose you were searching the keywords in the title before entering this page. The problem may be:

In a GridView (ASP.NET 2.0), you want to use a HyperLinkField, but you find it doesn't support UrlEncode, while you are planning to pass some variables via URLs. The bug report shows that Microsoft doesn't have any plan on adding such a property, because their policy on backward compatibility between different version of .net frameworks.

I also made a lot of searching and browsing. The popular way to solve this problem always is, to tranform your HyperLinkField into TemplateField, and do UrlEncode by yourself via HttpUtility.UrlEncode method.

Following codes give you another choice, avoiding such a tranformation, and working for your UrlEncode needs. Just have a try!

 

    public static void HyperLinkFieldUrlEncodeHack(GridView gridView)
    {
        if (gridView == null)
        {
            return;
        }
        gridView.RowDataBound += delegate(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }
            for (int i = 0; i < gridView.Columns.Count; i++)
            {
                DataControlField field = gridView.Columns[i];
                if (field is HyperLinkField)
                {
                    log.Debug(e.Row.RowType.ToString());
                    TableCell td = e.Row.Cells[i];
                    if (td.Controls.Count > 0 && td.Controls[0] is HyperLink)
                    {
                        HyperLink hyperLink = (HyperLink)td.Controls[0];
                        HyperLinkField hyperLinkField = (HyperLinkField)field;
                        if (!String.IsNullOrEmpty(
                            hyperLinkField.DataNavigateUrlFormatString))
                        {
                            string[] dataUrlFields = new string
                                [hyperLinkField.DataNavigateUrlFields.Length];
                            for (int j = 0; j < dataUrlFields.Length; j++)
                            {
                                object obj = DataBinder.Eval(e.Row.DataItem,
                                    hyperLinkField.DataNavigateUrlFields[j]);
                                dataUrlFields[j] = HttpUtility.UrlEncode(
                                    (obj == null ? "" : obj.ToString()));
                            }
                            hyperLink.NavigateUrl = String.Format(
                                hyperLinkField.DataNavigateUrlFormatString,
                                dataUrlFields);
                        }
                    }
                }
            }
        };
    }

 

Pleased if you find it useful.

posted on 2008-04-18 20:17:05 by percyboy  评论(0) 阅读(2816)

The virtual printer -- Microsoft Office Document Image Writer

You'll see a virtual printer named "Microsoft Office Document Image Writer" is added to your printers' list if you install Office 2003. Use this printer you may get a MDI file.

There are few articles over this function. But I found a good scenario, which this printer does the work perfectly.

(1) First use this printer to print files, like Word, Excel, PowerPoint, NotePad, web pages in browsers, emails in Outlook, pictures in Photoshop .... Yes, you convert files in different formats to a common format -- MDI format.

(2) Office 2003 also provides us a programming interface. We can get the texts in the MDI file via our codes. (only a few lines of codes, quite easily.) And then, you may use an indexing engine, like SQL Server's full-text search ability or NLucene, to create the indexes of the MDI files.

(3) An ActiveX control for viewing MDI files is also contained in Office 2003. You can drop this control onto your Windows Forms, and display a MDI file's content in the control.

Now, you convert the various formats' files to a single format for storing, and create indexes for these files. You may let your user query over the indexes (of cource, it may be full-text searching.), and display the match files in the ActiveX control mentioned above.

A simple "Document Management System" is created till here.


Maybe you have Adobe Acrobat family software (here EXCLUDE the Adobe Acrobat Reader), you also have a virtual printer, which will print out PDF format files. Yes, you may do the same thing just like the MDI solution does.

However, many customers may have Office 2003, or maybe it's in their future plan. The PDF solution need your customer purchase Acrobat's licences. That'll be another big budget.

(The original Chinese version is here.)

posted on 2004-11-10 10:40:00 by percyboy  评论(3) 阅读(33863)

Powered by: Joycode.MVC引擎 0.5.2.0