TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Manoj Maharana
NA
362
128.5k
How to add numbers in a text file together with file name
Apr 25 2019 11:45 PM
I want to check the size of text file i.e. if the file size is greater then 500kb then create another file with numbers.
Example:
Currently my file is saved like : NetApiLog_2019_04_25.txt
Here is the code to save file-
public
void
writeLogFile(
string
errorln)
{
FileStream fs =
null
;
try
{
var common = (ICommon)
new
CommonAttribute();
var netVpbxApiLogFlag = common.GetConfigurationByKeyName(
string
.Empty,
"NetVpbxApiLogFlag"
);
if
(Convert.ToBoolean(netVpbxApiLogFlag))
{
var logFilePath = common.GetConfigurationByKeyName(
string
.Empty,
"NetApiLogFilePath"
);
string
FileName =
string
.Format(
"{0}_{1}.txt"
, logFilePath,
DateTime.Today.ToString(
"yyyy_MM_dd"
));
if
(!Directory.Exists(logFilePath))
{
Directory.CreateDirectory(logFilePath);
}
fs =
new
FileStream(FileName, FileMode.Append, FileAccess.Write);
using
(StreamWriter sw =
new
StreamWriter(fs))
{
fs =
null
;
sw.WriteLine(
"Start VPBX Api."
);
sw.WriteLine(
"-------------------------------------------------------"
);
sw.WriteLine(
string
.Format(
"{0}:{1}"
, DateTime.Now.ToString(), errorln));
}
}
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
if
(fs !=
null
)
{
fs.Dispose();
}
}
}
If the file size is greater then 500kb then create the file like :
NetApiLog_1_2019_04_25.txt
if the size of file text file
NetApiLog_1_2019_04_25.txt greater then 500 kb then the name should be NetApiLog_2_2019_04_25.txt.
Can anyone help me to how to write in c# asp .net.??
Reply
Answers (
2
)
ebay tracking number upload
how to display list if data in DevExpress in MVC