.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

problem to convert special character in export to csv

Posted By:      Posted Date: September 09, 2010    Points: 0   Category :ASP.Net
I am using FIleStream object to write .csv file from dataTable/Dataset.It is working fine. But when i got special character in my DataTable like $, @, # ect. it will convert these convert in encoded form( which can't be readable i.e.  â,¬ etc). FileStream flStream;astrFileName = HttpContext.Current.Server.MapPath("~/files/FtpFiles/Download/") + astrFileName + ".csv";if (File.Exists(astrFileName)){flStream = new FileStream(astrFileName, FileMode.Truncate, FileAccess.Write);}else{flStream = new FileStream(astrFileName, FileMode.Create, FileAccess.Write);}StreamWriter objSw = new StreamWriter(flStream);DataTable objDt = idtInstance;//Get No Of Column in GridView int NoOfColumn = objDt.Columns.Count;//Create Header for (int i = 0; i < NoOfColumn; i++){objSw.Write(objDt.Columns[i]);//check not last column if (i < NoOfColumn - 1){objSw.Write("||");}}objSw.Write(objSw.NewLine);//Create Data foreach (DataRow dr in objDt.Rows){//if (dr["GCMSCaseNumber"].ToString() == "14222")//{// string desc = dr["Updates"].ToString();//}for (int i = 0; i < NoOfColumn; i++){string sData = dr[i].ToString();sData = sData.Replace("<br>", " ");sData = sData.Replace("<br/>", " ");sData = sData.Replace("\n", " ");sData = sData.Replace("\t", "

View Complete Post

More Related Resource Links

Special character problem



Using a gridView to read some data from a SQL database.

The user can select a record in the gridview.

On the SelectedIndexChanged property I populate this to a couple of text boxes & drop down list ; txtCountry,ddlProvince,ddlCity.

I have special characters in France ( accent marks) and when I populate it to the drop down list it fails giving out the error message

"SelectedValue which is invalid because it does not exist in the list of items".

Example of items that I try to populate are as follows. ( separated by commas)


When I looked in the drop down lists for Province and Cities  I see those Provinces there in the item list.

When I debug line by line the word ÃŽLE-DE-FRANCE comes out like  &#206;LE-DE-FRANCE  which is not there in the drop down list.  Got to know the ÃŽ is typed by pressing down ALT+206 and lloks like this is what is coming in at the start of the string above.

Any suggestions how to overcome this issue?


PS: The drop down lists for Province and Cities are also populated from the same SQL Database which has the above accent characters. The list that is displayed c

Crystal Report vs 2003 convert to vs 2008 parameter problem


Hi friend,

I have a project develop with Visual Studio 2003, when i convert the project to Visual Studio 2005 is work well. But when i convert to Visual Studio 2008, the crystal report when have pass parameter will prompt the parameter field to re-type then show the report.

But in this converted project i create a new report and pass the parameter is ok. That means i wan re-do all report @.@??

Does someone can help me solve this problem??

Thank you

XPS Export with images problem.

Hi, I have a drawing pad which is a Canvas which shapes can be added to in the form of Windows.Shapes.Shape.  These get drawn by overriding the DefiningGeometry property and setting the shapes values there. For images this looks like this Public Overrides Function Draw() As Geometry If Me.Pen.Thickness = 0 Then Return Nothing Dim rf As Rect = ReturnFixedRectangle() Me.Fill = Me.ImageBrush Dim mt As New MatrixTransform(Me.Matrix) m_rectangle.Rect = rf Me.VisualTransform = mt Return m_rectangle End Function Where Me.ImageBrush is Public Property ImageBrush() As ImageBrush Get If m_imageBrush Is Nothing Then m_bitmapStream = New System.IO.MemoryStream m_bitmapStream.Write(Me.ImageBytes, 0, Me.ImageBytes.Length) m_bitmapStream.Seek(0, IO.SeekOrigin.Begin) m_frame = System.Windows.Media.Imaging.BitmapFrame.Create(m_bitmapStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad) m_aspectRatio = m_frame.Width / m_frame.Height m_imageBrush = New ImageBrush(m_frame) m_imageBrush.Stretch = Windows.Media.Stretch.Fill m_imageBrush.TileMode = TileMode.None m_imageBrush.Freeze() m_bitmapStream.Close() End If Return m_imageBrush End Get Set(ByVal value As ImageBrush) m_imageBrush =

Export to CSV w/ grouping problem after 2005 upgrade

Hi,After upgrading to reporting services 2005 from 2000, reports that used to export to CSV correctly don't now. It appears the CSV export suddenly stops at a table with grouping. Any ideas would be appreciated...Thanks.

Cannot convert from 'int' to 'System.Data.OracleClient.OracleParameter' - Problem with OracleHel

Hi I downloaded the OracleHelper.cs & I use VisualStudio 2008,I'm suppose to pass values to a stored procedure which accepts 2 parametersWhen i pass from codebehind it says,Cannot convert from 'int' to 'System.Data.OracleClient.OracleParameter'Cannot convert from 'string' to 'System.Data.OracleClient.OracleParameter'The best overloaded method match for 'DataWrapper.ExecuteNonQuery(string, System.Data.CommandType, string, params System.Data.OracleClient.OracleParameter[])' has some invalid argumentsI'm posting mycode,Using STORED PROCEDURE,OracleHelper.ExecuteNonQuery (con, CommandType.StoredProcedure, "sample", Int32.Parse(TextBox1.Text),TextBox2.Text); Plz help !______________________________________If possible,  tell me a solution for this error too !http://forums.asp.net/t/1598804.aspx

How to prevent special character encoding when using xslt value in javascript variable

Hi, I've created a dataview and inserting a little bit of javascript. I need to store one of the xslt values into a javascript variable. The problem is that when I get the value into my javascript variable, it is already encoding special characters . for example, instead of "<", I get "&lt;" Am I doing something inaccurate here? I even tried using the javascript unescape() function, but that didn't work. would you be able to advise how to get the xslt value into a javascript variable as it is without having the original data changed? <xsl:template ... ... <SCRIPT type="text/javaScript"> <![CDATA[ ...     var myData = ']]><xsl:value-of select="@sampleData" disable-output-escaping="yes"/><![CDATA['  ;  ... ]]> </SCRIPT> Pman http://www.pmansLab.com/

special character wrongly inserted

I have a gridview with checkbox column.  I loop through all the rows of gridview, if it's checked I enter the second column text into my database.The second column text at one point shows the word  Küche, but when I take that text (in order to insert it in db) it gives me K&#252;cheand that's what I see when I then read it from db.

User Profile Sync - Profile Picture Export to AD Problem

To start, I think I've read every post/blog/etc there is on this subject.  Currently I have user profile import to Sharepoint 2010 working.  It imports profile data just fine.  Everything in the FIM Synchronization manager show success even.  Its the export from Sharepoint to AD of the user profile picture that isn't working at all.  I've gone thru the steps of adding the thumbnailphoto export under the picture properties.  I can see the export inside of the FIM manager.  I notice though that in FIM there is there a DS_EXPORT of the objects.  I've looked into the SyncDB and noticed in the metaverse table the SPS_MV_OctetString_PictureURL never gets updated with the information from the PictureURL column of the ProfileDB.  It is always Null.  Actually in FIM it only shows one person with an update, and keep showing the PictureURL property as being not applied, which is probably because it is showing it as blank only.  In the connector for the object in FIM, I get the error that I've seen in some blog posts where it says PictureURL (String) is not compatible with SPS_MV_OctetString_PicutreURL (binary), but that seems to be how Sharepoint builds the connection even though FIM finds it invalid.  I've had that created, deleted several times, so I guess that is ordinary, and not sure that is even the problem.

Data Type Convert problem?

1/2 is inputed by user, I hope to get the result 0.5, but both Method1 and Method2 get the result 0 How can I do? Thanks! BTW, I can't require user to input 1.0/2.0      Method1:     double my = 1/2;Method2:     double my = Convert.ToDouble(1/2);  

Problems with single quote character when attempting to export data from SQL Server

Hi, I am attempting to use the following query, which works fine when run in sql server management studio, to export data: SELECT             '1',             isnull(left(DISTRICT,1),' '),             isnull(left(CTV,2),'  '),             isnull(left(CTV2,5),'     ')           FROM [CensusData].[dbo].[MainQuestionnaire$] The export command follows: EXEC xp_cmdshell 'bcp "SELECT             '1',             isnull(left(DISTRICT,1),' '),             isnull(left(CTV,2),'  '),             isnull(left(CTV2,5),'     ')             FROM [CensusData].[dbo].[MainQuestionnaire$]" queryout "C:\bcptest.txt" -T -c -t -S "MYSERVER"' The error is: Incorrect syntax near '1'. I believe that the problem is with the single quote characters but don't know how to fix it. I am using SQL Server 2005 Express edition. Please help.

SQL convert problem / question


Hi all

Can somebody explain the following behavior:
The first and second query are quite clear but I
do not understand why the third query does not work ??

Thanks a lot for your comments !

Best regards
Frank Uray

-- Working
FROM [dbo].[GeoDataTest]

Best Method to remove special character from string

I am trying to remove the special characters from a string that was entered by the user.  I am not sure the best method to do this.  i can get a foreach of all the characters but what do i check it against?
Christian - developer

Interesting Problem WPF Visual to Image Convert.


I am converting the Canvas to Image By using

renderBitmap = new RenderTargetBitmap(desiredWidth, desiredHeight, 96d, 96d, PixelFormats.Pbgra32);// PixelFormats.Pbgra32);
                    //RenderOptions.SetEdgeMode(drawingVisual, EdgeMode.Aliased);
                    RenderOptions.SetBitmapScalingMode(drawingVisual, BitmapScalingMode.HighQuality );
                    drawingVisual.SnapsToDevicePixels = true;
                    var dv = new DrawingVisual();
                    using (DrawingContext ctx = dv.RenderOpen())

                        var vb = new VisualBrush(drawingVisual);

Regular Expression to avoid space and special character



I would like to have an regular expression that does not allow any spaces(before,within,after the word) and alphanumeric characters.

Thanks in advance.



Special Character Translation

I built a view in Designer that's pulling data from a list.  When I deployed the view to SharePoint, I discovered that special characters entered into the list don't display correctly.  For example, "-" is displayed as &#39.  Is there a solution for this translation issue?

Problem with xmlns when I convert object to XML and XML to object back


Hi, I am facing a strange problem.

I have a class object which I am accessing through webservice call.

Now actually that class has a property with type of Array inside that class and that array is the array of same class object. Means in reality, I have detailed tree structure as per how data gets fill up in that class object.

This is how my XML is and my actual code.

string xml_For_Obj = "";

                xml_For_Obj = "<xml version=\"1.0\" encoding=\"utf-16\">  ";
                xml_For_Obj += "    <ComponentObject xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
                xml_For_Obj += "        <BundledComponents xmlns=\"http://MySite.com/ISI/OtherWebService/Components\">";
                xml_For_Obj += "            <ComponentObject>";
                xml_For_Obj += "                <SKU>Test Sku Name</SKU> ";
                xml_For_Obj += "                <SubGroup>Test SubGroup</SubGroup> ";
                xml_For_Obj += "                <Quantity>70</Quantity> ";
                xml_For_Obj += "                    <BundledComponents >";

SSRS 2008 export to Excel margin problem

When rendering report from SSRS 2008 with custom margins (let's say 0.5in) into Excel, margins do not export correctly, or do not export at all, thus Excel sets its default margins.

I heard in SSRS 2005 it was not a problem.

Any ideas?
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend