create a file of particular size and save it to a dynamic location

Posted by santhoshvorugantiymail-13369 under C# on 1/14/2012 | Points: 10 | Views : 831 | Status : [Member] | Replies : 1
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........


Responses

Posted by: santhoshvorugantiymail-13369 on: 1/16/2012 [Member] Starter | Points: 25

Up
0
Down
there is mismatch in the variable kb.


bezwada santu........

santhoshvorugantiymail-13369, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response