|
Hi,
In my intranet application (VB.Net, Framework 2) when Iam trying to export data to csv format junk charaters are displayed in place of Arabic data...
When Iam tying to export the same data to Excel it is working fine...
What could be the reason why it is not displaying the junk characters....
Please guide what is going wrong...
Thanks
Imtiaz
Imtiaz A.K
|
|
|
|
|
What encoding are you using? When Unicode characters are included, you should save in Utf8 encoding.
|
|
|
|
|
Iam using the below code..
<br />
da = New SqlDataAdapter(sQuery, Conn)<br />
da.Fill(ds)<br />
Dim GridView1 As New GridView<br />
GridView1.AllowPaging = False<br />
GridView1.DataSource = ds<br />
GridView1.DataBind()<br />
Response.Clear()<br />
Response.Buffer = True<br />
Response.AddHeader("content-disposition", "attachment;filename=Report.csv")<br />
Response.Charset = ""<br />
Response.ContentType = "application/text"<br />
Dim sb As New StringBuilder()<br />
<br />
For k As Integer = 0 To ds.Tables(0).Columns.Count - 1<br />
sb.Append(ds.Tables(0).Columns(k).ColumnName + ","c)<br />
<br />
Next<br />
sb.Append(vbCr & vbLf)<br />
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1<br />
<br />
For k As Integer = 0 To ds.Tables(0).Columns.Count - 1<br />
'add separator <br />
'sb.Append(ds.Tables(0).Rows(i)(k).ToString().Replace(",", ";") + ","c)<br />
sb.Append(ds.Tables(0).Rows(i)(k).ToString() + ",")<br />
Next<br />
'append new line <br />
sb.Append(vbCr & vbLf)<br />
Next<br />
Response.Output.Write(sb.ToString())<br />
Response.Flush()<br />
Response.End()<br />
Is there anything wrong in this code...
But when Iam trying to export the same data to Excel it is working fine....
if the issue is with unicode then it should not also support the Excel....
Please guide..
Imtiaz
Imtiaz A.K
|
|
|
|
|
Try,
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "UTF-8";
|
|
|
|
|
no change..
same issue..
any other suggestion...
Imtiaz A.K
|
|
|
|
|
Well, csv is only comma-separated values. You can open it in Text editors. If you are downloading a unicode file and open in TextMode it will not be shown properly. try to open the same file in unicode editors. I think you can see them clearly.
Excel format is actually supports Unicode. So if you open a file containing unicode characters in Excel, it will be shown properly.
As Navaneeth suggested, you can make the file download using
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "UTF-8";
which will ensure that the data downloaded is parsed as Unicode.
|
|
|
|
|
As Iam exporting dataset to csv format ....
Iam opening it in excel only... still it is giving junk characters...please check the code I had added...
this code wil directly prompt a (Open/save)dialog box and when we click open it will open the file in excel...
Even though it is opened in Excel which supports Unicode characters, it is still showing junk values in place of arabic data...
Please suggest...
Thanks..
Imtiaz A.K
|
|
|
|
|
Hello all
When I buy domain and host what should I do to use databases and is database on my hard drive or it's on the server?
|
|
|
|
|
hasani2007 wrote: When I buy domain and host what should I do to use databases and is database on my hard drive or it's on the server?
It should be on server. And how to use it for that you need to contact with the Hosting Site Admin or try to read the help file for that.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello everyone, I always apologize for my English not perfect. Anyway I wanted to ask you how to load data in a DetailsView without using the SqlDataSource control. I want to load data using only C #, are familiar with the property "DetailsView1.DataSource = fuction ();"
but I'm not sure how it works, someone can explain it to me?
Here's the code that I wrote:
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
DetailsView1.DataSource = aggiorna();<br />
DetailsView1.DataBind(); <br />
}<br />
public DataTable aggiorna()<br />
{<br />
string IDModelloQ = Request.QueryString["IDModelloV"];<br />
SqlCommand comando = new SqlCommand();<br />
SqlConnection connessione = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);<br />
connessione.Open();<br />
comando.Connection = connessione;<br />
comando.CommandType = CommandType.Text;<br />
comando.CommandText = "SELECT * FROM Automobili WHERE IDModello=" + IDModelloQ;<br />
try<br />
{<br />
comando.ExecuteNonQuery();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
throw ex;<br />
}<br />
finally<br />
{<br />
connessione.Close();<br />
}<br />
return What must return!?<br />
}<br />
My problem is that I don't know that since returning from the function "aggiorna ()".
|
|
|
|
|
You are clueless.
To fill a DataTable , you need to use DataAdapter and call Fill on it. Your code also got several issues including SQL injection attacks and improper resource cleanup. Here is a modified version of your code.
public DataTable aggiorna()
{
string IDModelloQ = Request.QueryString["IDModelloV"];
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
string query = "SELECT * FROM Automobili WHERE IDModello = @IDModelloQ";
DataTable table = new DataTable();
using(SqlConnection connessione = new SqlConnection(connectionString))
using(SqlCommand comando = new SqlCommand(query, connessione))
{
comando.Parameters.AddWithValue("@IDModelloQ", IDModelloQ);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = comando;
adapter.Fill(table);
}
return table;
} Don't catch exceptions if you are not doing anything with that. Also
catch (Exception ex)
{
throw ex;
} is stupid. This will clear the stack-trace. To re-throw use just throw .
|
|
|
|
|
Oh I understand ... but I can not find examples with sqladapter!
And that means "clueless"? (I can not find a translation in Italian!)
I know that this code is dangerous and attacked via SQL injection. But how can I do? Through stored procedures?
I apologize but I'm a beginner!
|
|
|
|
|
|
|
_ASPAle_ wrote: I know that this code is dangerous and attacked via SQL injection. But how can I do? Through stored procedures?
The code which I provided takes care SQL injection problems. You do it by writing parameterized queries. The using block in my code ensures resources are properly cleaned up.
_ASPAle_ wrote: I apologize but I'm a beginner!
A book is best for absolute beginners rather than an Internet forum.
_ASPAle_ wrote: And that means "clueless"? (I can not find a translation in Italian!)
Dictionary[^]?
|
|
|
|
|
Will take care ok ... however I have already attended a course of a year to become "web designer", only that the world of Internet is so broad, I starts now to understand how powerful ASP.NET compared to other languages.
Many people underestimate, but wrong, especially those who are in favor of open source like PHP and company! PHP is not very functional for me.
|
|
|
|
|
_ASPAle_ wrote: I starts now to understand how powerful ASP.NET compared to other languages.
A small correction. ASP.NET is not a language. It is a framework which can be programmed using C# or VB.NET. C# and VB.NET are the languages.
|
|
|
|
|
just simply make a dataset and a datatable....
and use sqldataadapter instead of sqlcommand....
and fill the dataset using SqlDataAdapter.fill(Dataset ds, "<tablename>")
then make a datatable
DataTable dt = ds.Tables["<tablename>"];
then ur return statement...
return dt;
|
|
|
|
|
Dear All,
I am using asp.net 3.5 with Microsoft Reporting Service (RDLC).
My Application works fine in local machine. But when I upload my application in my real application server it shows the following error message
My real application server is a shared asp.net 3.5 hosting provider.
Can anyone advice to resolve it.
Server Error in '/' Application.
Required permissions cannot be acquired.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Policy.PolicyException: Required permissions cannot be acquired.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[PolicyException: Required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7604211
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57
[FileLoadException: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
[ConfigurationErrorsException: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +83
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +126
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +62
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
I have tried with crystal report too.
It shows the error as follows
Server Error in '/' Application.
Required permissions cannot be acquired.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Policy.PolicyException: Required permissions cannot be acquired.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[PolicyException: Required permissions cannot be acquired.]
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +7604211
System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +57
[FileLoadException: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
System.Reflection.Assembly.Load(String assemblyString) +28
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
[ConfigurationErrorsException: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +83
System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +126
System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) +62
System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +33
System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) +40
System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) +160
System.Web.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +93
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
|
|
|
|
|
I think this is the problem with Trust level.
The application requires Full / Medium trust level while you are running it in Low Trust level.
Open your web.config and add
<trust level="Medium" originUrl="" /> to your <system.web> section.
|
|
|
|
|
hello all
I have a question.
My website has fileupload control that everyone can send data as doc,jpg and etc. Now I want to know that when they upload their files, where were these files go? it means that the transferred files go to the internet and I should download them to access them or these files send to my computer directly and I shouldn't connect to internet to see uploaded files.
For example suppose that a person whose name is FIRST upload a word file(doc) for me in my site. now I want to access to it to read it. what should I do?
Should I connect to the server that I buy my host from it and download that file? or that file send to my hard drive directly and it's in my computer.
Does it have any relation to ftp? if it does please explain for me about ftp?
excuse me for low English and long text.
modified on Sunday, September 27, 2009 6:44 AM
|
|
|
|
|
hasani2007 wrote: Now I want to know that when they upload their files, where were these files go?
The file will save to your server on the path where you have mentioned in your code. I guess you used some thing like,
FileUpload1.SaveAs(filepath);
Where filepath is server path location. Make sure when you host the site on IIS, you need to give the proper persmission to that folder for giving user to write access permission. It will normally work from VS Studio as VC Intergrated ASP.NET Enginge having full rights to write on Local Disk, but when you will host on IIS you need to setup the permission.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hasaini wrote: I shouldn't connect to internet to see uploaded files.
Did You Get the Question.
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
hasani2007 wrote: Now I want to know that when they upload their files, where were these files go?
It Depends Upon The Code.Where You are go to save files Is it Database or Map Path
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|
hasani2007 wrote: download them to access them or these files send to my computer directly and I shouldn't connect to internet to see uploaded files.
Does it have any relation to ftp? if it does please explain for me about ftp?
Can You Explain this part in brief..!
Why Do Some People Forget To Mark as Answer .If It Helps.
|
|
|
|
|