|
It's depends on situtations.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hi.
i have one folder
ABC
--1.txt
--2.txt
I have to copy this file to another folder
XYZ
--11.txt
--12.txt
how can achive this task in vb.net....
Regards,
Hemant Patel.
|
|
|
|
|
This question has NOTHING to do with ASP.NET
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You mean both the folders in the server ???
If so,
why dont you use File.Copy(path1,path2)
|
|
|
|
|
Hemant_ec48 wrote: how can achive this task in vb.net....
Here is the way.
using System.IO
Public Sub CopyDir(ByVal strSrc As String, ByVal strDest As String)
Dim dirInfo As New DirectoryInfo(strSrc)
Dim fsInfo As FileSystemInfo
If Not Directory.Exists(strDest) Then
Directory.CreateDirectory(strDest)
End If
For Each fsInfo In dirInfo.GetFileSystemInfos
Dim strDestFileName As String = Path.Combine(strDest, fsInfo.Name)
If TypeOf fsInfo Is FileInfo Then
File.Copy(fsInfo.FullName, strDestFileName, True)
'This will overwrite files that already exist
Else
CopyDir(fsInfo.FullName, strDestFileName)
End If
Next
End Sub
But,as CG suggested this has nothing to with ASP.NET. You should always ask the question in proper fourm to get the better answer.
Thanks !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I have a textbox in the masterpage, then I input some text and click one button to redirect to another page,
then the text in this textbox dispears, my question is that how to keep the text displayed even after redirect to annother page?
I find one solution by using ((TextBox)Master.FindControl("TextBox_my")).Text =text_input;
but later, I try to change the text and click the button again, the text in this textbox will be never changed and is always the original one.
anyone can tell me why and any other solutions?
thanks.
|
|
|
|
|
Well Seraph,
The only case that your textbox value doesnt appear to the server side may arise if you textbox is either Enabled = "false" or Readonly = "true"
1 In case of <asp:textbox Enabled="false"
The form that holds the textbox doesnt submit itself. So the textbox will always appear to contain ""(Empty string) in the server side.
2. In case of <asp:textbox ReadOnly="true"
The form submits the textbox, but always the original value which is used to create the form retains in the server side. Thus any changes to the control doesnt appear.
Check whether your textbox is enabled or Readonly.
To transmit text from one page to another you might use querystring. Just place in your address
yourpage.aspx?x=name&y=age
But if the text is coming from the database, I would rather recommend you to fetch it from database every time, because, as this is web, the user might paste the link directly to the address bar rather than coming from the previous page.
|
|
|
|
|
Q1. Is there any way to return more than one value as one or more responseText variable by just running one ajax function.
-------
Q2. What is the form of 'responseText'? I think it isn`t just a char string, because whenever i compre it by a distinct value using IF, IF always return false!! My question is how to compare 'responseText' with some values and then choose the best operation or function for next step?
ThnQ All!
|
|
|
|
|
bijan.8k wrote: Q1. Is there any way to return more than one value as one or more responseText variable by just running one ajax function.
No... XMLHttpRequest object can be used to get only one response at a time. If you want response from two pages come from the server, you need to create 2 XMLHttpRequest object and call send method yourself. You cannot use the send method until the ReadyState = 4 [or error occured] , which means the response is received.
** If you want to know that is it possible to send 2 values from the server in the same response.. !! You can... You can even merge the 2 response from the server and return the single response to one XMLHttpRequest to the client.
bijan.8k wrote: Q2. What is the form of 'responseText'? I think it isn`t just a char string, because whenever i compre it by a distinct value using IF, IF always return false!! My question is how to compare 'responseText' with some values and then choose the best operation or function for next step?
Well, regarding your responseText , it totally depends on the server response. If you just return "abcd" it will hold the same thing. Moreover responseText is purely html when a page is requested. Just put a breakpoint(or simply put an alert) to the point where ReadyState = 4 for your request, and see what is within it.
To ensure you always get what you send from the server.. (at least when you just sending a string from the HttpHandler ) use :
Response.Clear();
Response.Write("your static string content");
Response.End();
Hope you got everything...
|
|
|
|
|
|
iserbrain wrote:
Subject: How to using webcam for live video on asp.net website ?
ASP.NET has nothing to do with Web Cam integration
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
This is very rude to delete message
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hi Guys,
I am working on a website and trying to create a web page with file uploader which can upload any type of file to the server.
Please help me with sample code.
Working on ASP.NET VisualStudio2008.
Thanks
|
|
|
|
|
Add
<asp:FileUpload ID="fuFile" runat="server" /> to you aspx page and a button.
the button "click event" code should look like this:
fuFile.SaveAs(Server.MapPath("~/folder/filename"))
|
|
|
|
|
string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1, File1.PostedFile.FileName.Length - File1.PostedFile.FileName.LastIndexOf("\\") - 1);
string StrFileType = File1.PostedFile.ContentType;
int IntFileSize = File1.PostedFile.ContentLength;
I am using this code...but its generating error..
|
|
|
|
|
Sr...Frank wrote: string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1, File1.PostedFile.FileName.Length - File1.PostedFile.FileName.LastIndexOf("\\") - 1);
string StrFileType = File1.PostedFile.ContentType;
int IntFileSize = File1.PostedFile.ContentLength;
Just use only
File1.SaveAs();
Sr...Frank wrote: I am using this code...but its generating error..
What error you are getting ?
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
You also have to add premmisions to that folder where you store the file
|
|
|
|
|
Blikkies wrote: You also have to add premmisions to that folder where you store the file
Yes, This is only needed when you deploy the application on IIS Server. Its not mandatory for when we are doing it for Visual Studio.
Because, In Visual Studio, ASP.NET Engine having all kind of permssion to write on your harddrive. But, when you put the applicaiton on IIS, the application will run on Network Service Identity . Which having very minimum permission rights , and not to write on disk.
So we can have two solution,
a) Give the write access to all the user for that particular folder where we are uploding the file.
b) Make a different application pool with Identity of Local System ( which having write access permission) and assign it to the virtual directiry.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Use FileUpload Control
Try to uplaod file using,
If(FileUpload1.HasFile)
{
FileUpload1.SaveAs(path);
}
This code will work fine when you run your application from VS IDE . but when you deploy your code on IIS, you need to give the Access permission to the folder for user to upload file or you need to create a separate application pool for your site with Local System Identity .
Please let me know if you have any issue .
Thanks !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hi ,
i have created a user control numberbox which is working fine .
But i want set the property value from aspx.cs file dynamically which is not possible . it is taking the value from toolboxdata table only even though i set the property in page load.
numberbox code:
using System.Collections.Generic;
using System.Text;
using System;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
namespace ERP.Controls
{
[
ToolboxData("<{0}:NumBox runat=server></{0}:NumBox>"),
DefaultProperty("DecimalPlaces")
]
public class NumBox : TextBox
{
private int mDecimalPlaces = 0;
private char mDecimalSymbol = '.';
private bool mAllowNegatives = true;
[
Bindable(true),
Category("Appearance"),
DefaultValue(typeof(int), "2"),
Description("Indicates the number of decimal places to display.")
]
public virtual int DecimalPlaces
{
get { return mDecimalPlaces; }
set { mDecimalPlaces = value; }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue("."),
Description("The digit grouping symbol.")
]
public virtual char DecimalSymbol
{
get { return mDecimalSymbol; }
set { mDecimalSymbol = value; }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(true),
Description("True when negative values are allowed")
]
public virtual bool AllowNegatives
{
get { return mAllowNegatives; }
set { mAllowNegatives = value; }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(0),
Description("Indicates the number of decimal places to display.")
]
public virtual double Value
{
get
{
try
{
return ParseStringToDouble(this.Text);
}
catch (FormatException e)
{
throw new
InvalidOperationException("NumberBox does not contain a valid Number.");
}
catch (Exception e)
{
throw e;
}
}
set
{
if ((value < 0) & !AllowNegatives)
throw new
ArgumentOutOfRangeException("Only positive values are allowed for this NumberBox");
base.Text = value.ToString(GetFormat()).Replace(".", DecimalSymbol.ToString());
}
}
override public string Text
{
get
{
return base.Text;
}
set
{
try
{
this.Value = ParseStringToDouble(value);
}
catch (FormatException e)
{
base.Text = value;
}
catch (Exception e)
{
throw e;
}
}
}
override protected void OnPreRender(EventArgs e)
{
if (this.Page.Request.Browser.JavaScript == true)
{
StringBuilder s = new StringBuilder();
s.Append("\n<script type='text/javascript' language='JavaScript'>\n");
s.Append("<!--\n");
s.Append(" function NumberBoxKeyPress(event, dp, ml, dc, n) {\n");
s.Append("var srcElement = event.srcElement ? event.srcElement : event.target;\n");
s.Append(" var myString = new String(srcElement.value);\n");
s.Append(" var pntPos = myString.indexOf(String.fromCharCode(dc));\n");
s.Append(" np=ml-dp-1;\n");
s.Append(" var obid = srcElement.id ;\n");
s.Append("var keyChar = event.which;\n");
s.Append("if (keyChar == null){\n");
s.Append("keyChar = event.keyCode; }\n");
s.Append("var r;\n");
s.Append("var Curpos=-1;\n");
s.Append("Curpos = srcElement.selectionStart;\n");
s.Append("if (Curpos!=-1){\n");
s.Append("if( document.selection ) { \n");
s.Append(" r = document.selection.createRange();\n");
s.Append("r.moveStart('character', -myString.length); \n");
s.Append("Curpos =r.text.length;}}\n");
s.Append(" if ((keyChar < 48) || (keyChar > 57) ) {\n");
s.Append(" if (keyChar == dc) {\n");
s.Append(" if ((pntPos != -1) || (dp < 1)) {\n");
s.Append(" return false; \n");
s.Append(" } }\n");
s.Append("else \n");
s.Append("if ((keyChar == 8) || (keyChar == 0)){\n");
s.Append("return true;\n}");
s.Append(" else \n");
s.Append("if (((keyChar == 45) && (!n || myString.length != 0)) || (keyChar != 45)) \n");
s.Append(" return false;\n");
s.Append(" }\n");
s.Append(" else \n");
s.Append(" { if ( myString.length > np-1 && pntPos ==-1 ) { \n");
s.Append(" return false; } \n");
s.Append(" else if (pntPos!=-1){\n");
s.Append(" var dsubstring ; \n ");
s.Append(" var ssubstring ; \n ");
s.Append("ssubstring=myString.substring(0,pntPos); \n");
s.Append("dsubstring=myString.substring(pntPos+1); \n");
s.Append("if (dsubstring.length > dp-1 ){\n");
s.Append(" if( Curpos > pntPos){ return false;} } \n");
s.Append("if (ssubstring.length > np-1) { \n");
s.Append(" if(Curpos < np+1){ return false; }}\n");
s.Append("}}\n");
s.Append(" return true;\n");
s.Append(" }\n");
s.Append("// -->\n");
s.Append("</script>\n");
this.Page.RegisterClientScriptBlock("NumberBoxKeyPress", s.ToString());
try
{
this.Attributes.Remove("onKeyPress");
}
finally
{
this.Attributes.Add("onKeyPress", "return NumberBoxKeyPress(event, "
+ DecimalPlaces.ToString() + ", "
+ MaxLength.ToString() + ", "
+ ((int)DecimalSymbol).ToString() + ", "
+ AllowNegatives.ToString().ToLower() + ")");
}
}
}
virtual public string ValidationRegularExpression
{
get
{
StringBuilder regexp = new StringBuilder();
int NumberPlaces1 = MaxLength - DecimalPlaces - 1;
if (DecimalPlaces > 0)
{
regexp.Append("^\\d{1,");
regexp.Append(NumberPlaces1);
regexp.Append("}(\\");
regexp.Append(DecimalSymbol);
regexp.Append("\\d{1,");
regexp.Append(DecimalPlaces.ToString());
regexp.Append("})?$");
}
else
{
regexp.Append("^\\d{1,");
regexp.Append(NumberPlaces1);
regexp.Append("}$");
}
return regexp.ToString();
}
}
virtual protected double ParseStringToDouble(string s)
{
if (s == "")
{
s = "0";
}
s = s.Replace(DecimalSymbol.ToString(), ".");
return double.Parse(s);
}
virtual protected string GetFormat()
{
StringBuilder f = new StringBuilder();
f.Append("0");
if (DecimalPlaces > 0)
{
f.Append(".");
f.Append('0', DecimalPlaces);
}
return f.ToString();
}
}
}
In aspx page have added the control.
<rit:numberbox id="numOne" runat="server" DecimalSymbol="." MaxLength="8" Value="34" AutoPostBack="True" DecimalPlaces="3" CausesValidation="True" >34.00</rit:numberbox>
and in cs file have given in page load :
protected void Page_Load(object sender, System.EventArgs e)
{
numOne.DecimalPlaces = 4;
}
which is not been set. i.e the property value is not able to set dynamically .
i.e from cs file . it is taking the value set initially not overridded.
please help in this regard.
Thanks and Regards,
sriharsha
|
|
|
|
|
We don't need to see all of your code, only the relevant bits. Most will just ignore a post with this much code.
only two letters away from being an asset
|
|
|
|
|
I think the value of the DecimalPlaces property is not stored in ViewState. You need to override LoadViewState and SaveViewState methods in the Custom Control.
modified on Wednesday, September 2, 2009 12:37 PM
|
|
|
|
|
I guess too.
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hi,
I am having web application and windows application. Now I want to store all database tables information(server database) into the cache. I don't want any local database to store servers database. I want to use cache. Just like replica of the servers database These information can be access by windows application program. after updating cache information these information can be update to again web servers database.
How can I do? Is there any other solution so that I can use server database locally for some time , update some tables information to locally and the again update to servers database i.e. overwrite it to servers database only those which is updated locally.
Thanks
sjs4u
|
|
|
|
|
Do you want to cache information locally using your windows application or web application?
You cannot cache replica of server database tables locally using web appliction.
You can use SQL Server 2005 Express Edition if you want to do it using Windows application.
|
|
|
|