c#,asp.net
i am creating a text file using File.WriteAllBytes of particular size ie in kb or mob or bytes.
i have texrt box to enter size of file to be created
1 combo box for selecting size in mem i.e bytes or kb/mb
here is the code.....
public void AddFakeFileCreatorToDB(string SelectedFileSizeInMemory, int FileSize)
{
long index = Convert.ToInt64(FileSize);
var bytes = new byte[index];
Random r = new Random();
r.NextBytes(bytes);
//file size in bytes
if (SelectedFileSizeInMemory == "bytes")
{
File.WriteAllBytes("E:\\output -file bytes.txt", bytes);
}
//file size in kb
if (SelectedFileSizeInMemory == "kb")
{
index = index*1024;
File.WriteAllBytes("E:\\output-filekb.txt", bytes);
}
//file size in mb
if (SelectedFileSizeInMemory == "mb")
{
index = index*1024*1024;
File.WriteAllBytes("E:\\output-filemb.txt", bytes);
}
}
1st issue:
in the above code when i select size as kb/mb but it is creating the file in bytes only
ex if i enter 5 as size and select file size as mb but it is creating 5bytes only
can i know where is the mistake
2nd: issue
i am saving the location in static loacation in above code it is "E:\\output-filekb.txt",,,,, but i need to save the created file using to a dynamic location
bezwada santu........