|
Hi friends,
I want to upload and download .txt file in my web application.
Uploading part is completed successfully but when I am download the same file and reopen it,it contain complete html code of current page why this is so.
In case of .doc file this problem not occured.
Code snap is given below.
Public Sub Download(ByVal _fileName As String)
Try
Dim root As String = Server.MapPath("..\Operations\files\")
Dim sb As New StringBuilder(2048)
Dim f As String
Dim filename As String = _fileName
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(root + (Server.UrlEncode(filename)))
Catch ex As Exception
End Try
End Sub
I hope somebody help me.
Regards,
Nagraj
-- modified at 1:05 Tuesday 5th December, 2006
|
|
|
|
|
hi,
simply pass the address of the file in the navigateUrl of link
hypLink.NavigateUrl = "../files/test.txt"
or
hypLink.NavigateUrl = "../files/test.doc"
you wouldn't have to do all the complex coding that you are doing right now.
regards,
Kapil Thakur
|
|
|
|
|
Hi Kapil,
This is nice idea.
It's ok for .doc file but if navigateurl is .txt file it will not show prompt for OPEN/SAVE/CANCEL.
Please check this.
Regards,
Nagraj
|
|
|
|
|
Hello ,
I got the solution I would like to share with you all.
Public Sub download(ByVal _fileName As String)
Dim fs As System.IO.FileStream = Nothing
fs = System.IO.File.Open(Server.MapPath("..\Operations\files\" + _fileName), System.IO.FileMode.Open)
Dim btFile(fs.Length) As Byte
fs.Read(btFile, 0, fs.Length)
fs.Close()
With Response
.AddHeader("Content-disposition", "attachment;filename=" & _fileName)
.ContentType = "application/octet-stream"
.BinaryWrite(btFile)
.End()
End With
End Sub
Regards,
Nagraj
|
|
|
|
|
Hi All,
I have a page in which I have used <ifram> in which another page is included. In that <ifram> page there is text box named txtPO. I want to use that txtPO in the parent page and want to store its value in a variable i-e strPO. How is that posible. (ASP.NET and VB.NET) Please explain with example.
|
|
|
|
|
How is the page included?
---
b { font-weight: normal; }
|
|
|
|
|
Page is included in iframe. "iframe"
|
|
|
|
|
Then they are effectively in different windows in the browser. You have to use client side scripting, i.e. Javascript, to access the page and it's elements.
---
b { font-weight: normal; }
|
|
|
|
|
hi,
make a Public Property of that textbox.
then you will be able to retreive its value
Public Property txtName As String
Get
Return strName
End Get
Set
strName = textBox1.text
End Set
End Property
using this way, you can retrieve the value entered in the textbox
thanks,
Kapil Thakur
(Where's there is Kapil , there is a way)
|
|
|
|
|
Dear Kapil I have include that page in iframe. where should i creat public property of that textbox.
With Best Regards
Thankx
|
|
|
|
|
Hi,
Myself imran, I am quite new to dotnet. i am developing web application using asp.net and C#(Visual Studio 2005). i have defined connection string in web-config.
Can any one help me to know How to Access database using this connetion string.
thanks
regards
imran khan
|
|
|
|
|
Welcome to The Code Project.
Please don't post the same question all over the place. Pick the forum that best fits your question.
---
b { font-weight: normal; }
|
|
|
|
|
Please give me ur email address i will send u webconfig file. Modify it and give ur database path there. U will access ur database.
|
|
|
|
|
my mail id is imranafsari@gmail.com.
i have defined connection string in web-Config as
connectionStrings
add name="connstr" providerName="System.Data.SqlClient" connectionString="server=local;database=HFSERVICES;uid=sa;pwd=;"
/connectionStrings
Now i want to access this connection string in Default.aspx.cs
Thanks
-- modified at 1:52 Tuesday 5th December, 2006
-- modified at 1:54 Tuesday 5th December, 2006
regards
imran khan
|
|
|
|
|
|
Hi
How to pass argument from server side to javascript function?
Like
Dim index1 As Integer
index1 = index + 1
'index = e.Item.DataSetIndex()
CType(btn, HtmlInputButton).Attributes.Add("onclick", "mybtn(index1);")
this is my server side code and mybtn is my javascript function.
I want to pass index1 which is my variable as argument in my function.
How to do that?
Thanks
monika
|
|
|
|
|
You can't pass a server side variable as a parameter to a client side script. The server variable and the client script never exist at the same time, and never at the same place.
You have to use the value of the variable and put that in the string:
"mybtn(" & index1.ToString() & ");"
---
b { font-weight: normal; }
|
|
|
|
|
hi,
in <HTML> code of design view.
use the document.getElementById( 'server-control id') to fetch the server-controls value.
if you find out someother way. please let me know also.
thanks,
Kapil Thakur
(Where's there is Kapil , there is a way) - thakur.kapil@gmail.com
|
|
|
|
|
hi
thanks for yr kind response.
But yr logic is not possible in my logic.
I have found anothere solution
CType(btn, HtmlInputButton).Attributes.Add("onclick", "mybtn(" & index1.ToString() & ");")
I hope u r getting.
Thanks
monika
|
|
|
|
|
Invalid postback or callback argument. Event validation is enabled using <pages enableeventvalidation="true"> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
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.
I got this Error when I clicked Button in Repeater control.
I defined <pages enableeventvalidation="false"> in Web.Config And Machine.Config files Still the error is there.
Polease guide.
yog
hui gfgh kgdgrt njjn hjgkn
|
|
|
|
|
This error is common in ASP.NET 2.0 as by default the EnableEventValidation is set to true for all the web pages. This provides an enhanced security mechanism where each of the event used in a web page must be registered prior to execution. Where ever you are using AJAX or non-registered CallBack methods, ensure to disable this "EnableEventValidation=false". Now you can work freely.
Arun
|
|
|
|
|
I want to show on Column called Sr No in my datagrid. At runtim this column will show values like 1,2,3.... for each selected row based on the records available in dataset. How to acheive this!!!!!!!
Thanks,
Mini Thomas
|
|
|
|
|
you can create an Autoincrement column and seed by 1 and bind with sr. no column.
Be
Bye
|
|
|
|
|
hi,
here is the code to display Sr No. in datagrid. In the following code loadDs is dataset.
if (loadDs.Tables.Count > 0)
{
loadConsultant.Tables[0].Columns.Add(new DataColumn("Sl_NO", System.Type.GetType("System.String")));
foreach (DataTable table in loadConsultant.Tables)
{
int i = 1;
foreach (DataRow row in table.Rows)
{
foreach (DataColumn column in table.Columns)
{
row["Sl_NO"] = i.ToString();
}
i = i + 1;
}
}
}
Regards,
Prya
|
|
|
|
|
Hello Prya,
In ur code how do I bind the row with Datagrid
also there is error on line
foreach (DataColumn column in table.Columns)
{
can u help mi out
Thanks,
Mini Thomas
|
|
|
|