Modify the fck editor -- FCKeditor v2.x automatically renames the uploaded files in Asp.net and saves the files by year and month.

Source: Internet
Author: User
By default, FCKeditor does not change the name of the file to be uploaded. Therefore, for servers that do not support Chinese names, files with Chinese names uploaded locally cannot be accessed.
It is still saved to the server using the date and time naming method.

The whole process is to modify the source code of fck. net, compile and generate the directory where fredck. fckeditorv2.dll is stored in Bin.

Three changes are made:
Uploader. CS (fast upload, file rename)
Filebrowserconnector. CS (Upload by directory, rename the file)
Fileworkerbase. CS (stores files by year/year directory)

Use vs. Net to open fredck. fckeditorv2.csproj, open the uploader. CS file, and find 47 lines.

Int icounter = 0;

While (true)

{

String sfilepath = system. Io. Path. Combine (this. userfilesdirectory, sfilename );

If (system. Io. file. exists (sfilepath ))

{

Icounter ++;

Sfilename =

System. Io. Path. getfilenamewithoutextension (ofile. filename) +

"(" + Icounter + ")" +

System. Io. Path. getextension (ofile. filename );

Ierrornumber = 201;

}

Else

{

Ofile. saveas (sfilepath );

Sfileurl = This. userfilespath + sfilename;

Break;

}

}

This part of the Code indicates that the Upload File name is named according to the original file name. If there is a same name, add (n) to identify it.

Modify it

While (true)

{

// Rename the file

Sfilename = "hztt _" + datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS fff "). Replace (" "," _ "). Replace (": ","-") +
System. Io. Path. getextension (ofile. filename );

String sfilepath = system. Io. Path. Combine (this. userfilesdirectory, sfilename );

Ofile. saveas (sfilepath );

// Output by year/month/directory

Sfileurl = This. userfilespath + datetime. Now. tostring ("yyyy-mm") + "/" + sfilename;

Break;

}

Datetime. Now. tostring ("yyyy-mm-dd
Hh: mm: SS ") is a string that obtains the current time and converts it to a formatted string. The result is 16:05:09.
123 format. The uploaded files are stored on the server as a Hztt_2007-07-01_16-05-09_123.gif.

Open the filebrowserconnector. CS file, find the fileupload function section in the Command handlers area, and modify row 215.

Int icounter = 0;

While (true)

{

String sfilepath = system. Io. Path. Combine (sserverdir, sfilename );

If (system. Io. file. exists (sfilepath ))

{

Icounter ++;

Sfilename =

System. Io. Path. getfilenamewithoutextension (ofile. filename) +

"(" + Icounter + ")" +

System. Io. Path. getextension (ofile. filename );

Serrornumber = "201 ";

}

Else

{

Ofile. saveas (sfilepath );

Break;

}

}

Modify:

While (true)
{

// Rename the file

Sfilename = "hztt _" +
Datetime. Now. tostring ("yyyy-mm-dd hh: mm: SS fff"). Replace ("",
"_"). Replace (":", "-") + system. Io. Path. getextension (ofile. filename );

String sfilepath = system. Io. Path. Combine (sserverdir, sfilename );

Ofile. saveas (sfilepath );

Break;

}

 

The uploaded files are also stored in the corresponding custom directory on the server (custom directory such as file image flash) in the name of Hztt_2007-07-01_16-05-09_123. GIF ).

 


Store files by month/year directory
Open the filebrowserconnector. CS file and modify lines 74.

Protected string userfilesdirectory
{
Get
{
If (suserfilesdirectory = NULL)
{
// Get the local (server) directory path translation.
Suserfilesdirectory = server. mappath (this. userfilespath );
}
Return suserfilesdirectory;
}
}

 

The function is used to save the image path and modify it:

Protected string userfilesdirectory
{
Get
{
If (suserfilesdirectory = NULL)
{
String userpath = server. mappath (this. userfilespath + datetime. Now. tostring ("yyyy-mm "));

If (! System. Io. Directory. exists (userpath) // create a folder
{
System. Io. Directory. createdirectory (userpath );
}
// Get the local (server) directory path translation.
Suserfilesdirectory = userpath;
}
If (! Suserfilesdirectory. endswith ("/"))
Suserfilesdirectory + = "/";
Return suserfilesdirectory;
}
}

 

Save the modified three Cs files, regenerate the solution, and overwrite the original fredck. fckeditorv2.dll in the \ bin \ DEBUG directory.

Click here to download related files

Upload/1/2007-42618-1-13.rar

The compressed package includes:

The bin directory contains the generated fredck. fckeditorv2.dll file.

The FCKeditor. net_2.2 source code of fck is in the backup directory,

The rest are the modified source code, which can be directly modified on this basis.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.